开发者

How Pick a Column Value from a ListView Row - C#.NET

开发者 https://www.devze.com 2022-12-31 00:58 出处:网络
alt text http://img153.imageshack.us/img153/9417/snapshotapp.jpg How can i fetch the value 500 to a variable fr开发者_高级运维om the selected row?

alt text http://img153.imageshack.us/img153/9417/snapshotapp.jpg

One solution would be to get the row position number and then the CustomerID position number. Can you please give a simple solution.

  • SelectedItems means selected row and SubItems means the column values, so SelectedItem 0 and SubItem 0 would represent the value 500. Right?

This is how i populate the listview:

            for (int i = 0; i < tempTable.Rows.Count; i++)
            {
                DataRow row = tempTable.Rows[i];

                ListViewItem lvi = new ListViewItem(row["customerID"].ToString());
                lvi.SubItems.Add(row["companyName"].ToString());
                lvi.SubItems.Add(row["firstName"].ToString());
                lvi.SubItems.Add(row["lastName"].ToString());

                lstvRecordsCus.Items.Add(lvi);
            }


If you use a DataGridView, a BindingSource and databinding for the texBoxes the whole problem is solved automatically.
Any reason you are not using databinding here?

But you can also assign your Row object to the ListViewItem.Tag property, that makes it easier to find your data back.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号