none
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

Answers

  • 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;
             if(!comboBox1.Items.Contains(text))
             {
                comboBox1.Items.Add(text);
             }
             comboBox1.SelectedItem = text;

    Thursday, May 26, 2016 11:25 PM