locked
how to retrieve data from listview to textbox? RRS feed

  • Question

  • listview1 in Fullrowselect

      Id Number    |  Name

              1         |       a

              2         |       b        

              3         |       c

    help! how can i retrieve the data from listview and display it in two textbox(txtboxID,txtboxName)?

     

    Friday, September 1, 2006 6:23 AM

Answers

  • Try something like this:

        private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
          if (listView1.SelectedItems.Count > 0) {
            ListViewItem itm = listView1.SelectedItems[0];
            textBox1.Text = itm.SubItems[0].Text;
            textBox2.Text = itm.SubItems[1].Text;
          }
        }

    Friday, September 1, 2006 3:31 PM
    Moderator

All replies

  • well which data do you want to retrieve? you usually go through the items property of the listview to get to the data you like.
    Friday, September 1, 2006 1:03 PM
  • Try something like this:

        private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
          if (listView1.SelectedItems.Count > 0) {
            ListViewItem itm = listView1.SelectedItems[0];
            textBox1.Text = itm.SubItems[0].Text;
            textBox2.Text = itm.SubItems[1].Text;
          }
        }

    Friday, September 1, 2006 3:31 PM
    Moderator