ListView控件演示07:获取列表中所有选定项的索引集合
2010-05-29 14:11
393 查看
此代码主要用来演示ListView.SelectedIndices属性。
即获取ListView列表中所有选定项的索引集合。
代码实现的功能:计算用户选定的早餐所需花费的价值。
选择多个项列表
计算早餐花费
即获取ListView列表中所有选定项的索引集合。
代码实现的功能:计算用户选定的早餐所需花费的价值。
选择多个项列表
计算早餐花费
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Demo07 { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } /// <summary> /// 初始化列表中的数据。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { string[] FoodList = new string[]{"Juice", "Coffee", "Cereal & Milk", "Fruit Plate", "Toast & Jelly", "Bagel & Cream Cheese"}; string[] FoodPrice = new string[]{"1.09", "1.09", "2.19", "2.49", "1.49", "1.49"}; this.BreakfastListView.BeginUpdate(); for (int Index = 0; Index < FoodList.Length; Index++) { ListViewItem Item = new ListViewItem(); Item.Text = FoodList[Index]; Item.SubItems.Add(FoodPrice[Index]); this.BreakfastListView.Items.Add(Item); } this.BreakfastListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); this.BreakfastListView.EndUpdate(); } /// <summary> /// 计算用户选中的早餐所需的花费。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CalculateButton_Click(object sender, EventArgs e) { double Price = 0; ListView.SelectedIndexCollection SelectedIndexes = this.BreakfastListView.SelectedIndices; foreach (int Index in SelectedIndexes) { double ItemPrice = double.Parse( this.BreakfastListView.Items[Index].SubItems[1].Text); Price = Price + ItemPrice; } MessageBox.Show(string.Format("所选的早餐需要花费{0}人民币!", Price)); } } }
相关文章推荐
- ListView控件演示05:获取指定坐标点的列表项
- ListView控件演示08:获取列表中的所有选定项
- 怎么从邮箱中获取所有联系人列表
- SQL获取所有数据库名、表名、储存过程以及参数列表
- 一个获取列表页面上所有CheckBox的脚本
- SQL获取所有数据库名、表名、储存过程以及参数列表
- 给你一个字符串s和一个长度相同的单词列表。 找出s中所有子字符串的起始索引,这些字符串中的每个单词只是一个字符串,没有任何中介字符。
- C++获取目录下所有文件列表函数
- ExcelUtils遍历集合时获取当前的索引
- javascript和jquery中获取列表的索引
- SQL Server 获取表的所有索引
- SQL获取所有数据库名、表名、储存过程以及参数列表
- SQL获取所有数据库名、表名、储存过程以及参数列表
- Java动态获取某个接口下所有的实现类对象集合
- python中获取指定目录下所有文件名列表的程序
- 集合是否包含某些元素,获取元素索引位置,元素排序(三)
- 获取控件所有事件列表
- c# 获取文件夹下面所有文件夹列表
- 超图 获取空间所有集合
- js获取select 下拉列表中的所有值