show selecteditem in listview in combobox RRS feed

  • Question


    hello,i need help: to show text from listviw1 in combobox1 ,when i click in listview,i  have no problem,if i put combobox1 in drop down in dropdown style in propreties,and i get simply the text from listviewwhen click.but if i select drop down list ,it don't work.

    private void listView1_Click(object sender, EventArgs e)

                btnupdat.Enabled = true;        // show button delet
                btndlt.Enabled = true;        //
                btnadd.Enabled = false;
                firstnametxt.Text = listView1.SelectedItems[0].SubItems[1].Text;
               lastnametxt.Text = listView1.SelectedItems[0].SubItems[2].Text;
                combobox1.SelectedItem = listView1.SelectedItems[0].SubItems[2].Text;  // here the problem i need to                                                                                                                                              //selected item in combobox1

    Thursday, May 26, 2016 7:22 PM


  • Greetings Foxnight.

    What you have done should work only if the ListView text is already in the ComboBox as an item. If it is not, you must add it first.

             string text = listView1.SelectedItems[0].SubItems[2].Text;
             comboBox1.SelectedItem = text;

    • Proposed as answer by Albert_Zhang Monday, May 30, 2016 2:48 AM
    • Marked as answer by DotNet Wang Monday, June 6, 2016 3:27 AM
    Thursday, May 26, 2016 11:25 PM