Populating a combobox with a listview
-
Is there a way to populate a combobox wiht data in a listview. And use the combobox in different forms. For example the listview on form1 contains fist name column, last name column, and account number column. On Form2 I have 3 textboxes (firstName, LastName, accountNumber)a combobox that I want to contain data from the listview on form1. When the user selects an item in the combobox I want it to fill the textboxes with the appropriate data. :confused:
-
Is there a way to populate a combobox wiht data in a listview. And use the combobox in different forms. For example the listview on form1 contains fist name column, last name column, and account number column. On Form2 I have 3 textboxes (firstName, LastName, accountNumber)a combobox that I want to contain data from the listview on form1. When the user selects an item in the combobox I want it to fill the textboxes with the appropriate data. :confused:
to make the comboBox contain the same data of the listview(limited to 1 column only) you can set the DataSource property of the comboBox to listView1.Items and the DisplayMember property to Text . in the SelectedIndexChanged event of listView1 object , edit the Text property of the 2 textBoxes:
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e) { textBox1.Text=listView.SelectedItems[0].Text; textBox2.Text=listView.SelectedItems[0.SubItems[0].Text; }