views:

41

answers:

1

alt text

  • How can i fetch the value 500 to a variable from the selected row?

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);
            }
+1  A: 

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.

Henk Holterman
I'm new to this, so i just try to achieve the functionality then i will focus how to improve the coding. Based on the requirement, i have to use ListView instead of DataGridView
peace
But your ListView looks just like a Grid. Why not use the right tool?
Henk Holterman
And, "achieve the functionality" the wrong way can become very expensive. Better think ahead a little.
Henk Holterman
"the wrong way can become very expensive"Hmmm, you are right, i will re-look at it...
peace
Basically, i'm using ListView since the records will be as read only, so ListView would work fine. What i know the main difference between GridView and ListView is GridView is read/edit whereas ListView is read only.
peace
I got it. I just forgot to call the listview design name...I was just exhausted.
peace
@peace: A gridView can be used as readonly as well (FullRowSelect).
Henk Holterman