简体   繁体   中英

how to connect my combox with textbox

i have connected my combox with my database

when the combox change's the value then my textbox should show the corresponding value in the textbox

You need to subscribe to SelectionChanged event of your ComboBox, then in eventhandler method use the following

if (comboBox.SelectedItem == null) 
{
   textBox.Text = string.Empty; //or any default value
   return;
}
textBox.Text = comboBox.SelectedValue.ToString();

You need to hook up the SelectedIndexChanged event. Depending on whether this is a WinForms or Web App will determine the exact code but ultimately they're pretty much the same.

我认为您可以使用绑定来做到这一点。

txtbox.DataBindings.Add("Text", comboBox, "Text")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM