how can I fill in a textbox when selecting an element of a comboBox?

-1
Private void pruebas_load(object sender, EventsArgs e)
{ 
  If (cb2.selectedIndex >0)
   {
     String[] valores = combo.captar_info(cb2.text)
     Txtcosto.text = valores[0];
   }
}

This is the code so that when selecting an element of a combobox the textbox is filled and it does not.

    
asked by Martin Bernal 28.11.2017 в 22:25
source

2 answers

0

If you mean to obtain the value of the selected item in the ComboBox and insert it into the TextBox, you have to use Events provided by the ComboBox element that jumps when performing / doing actions on that element, in this case you need the use of the event "SelectedValueChanged":

private void cb2_SelectedIndexChanged(object sender, EventArgs e){
    if (cb2.SelectedIndex == 0) {
            Txtcosto.Text = "";
    } else {
            Txtcosto.Text = combo.captar_info(cb2.Text)[0];
    }
}
    
answered by 28.11.2017 в 22:47
0

It could also be

private void cb2_SelectedIndexChanged (object sender, EventArgs e) {

   textbox.text = combobox.selectitem();
    o
   textbox.text = combobox.text;

}

    
answered by 30.11.2017 в 17:05