简体   繁体   中英

Update TextBox C#

I'm new in GUI development, especially in C#. I'm not able to update the UI when I change internally the property Text of a TextBox. I know there an TextChanged Event, but I think it is fired only when an user types into the textbox.

Here is my code :

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    int curItem = this.listBox1.SelectedIndex;
    StockItem it = this.model.Items.ElementAt(curItem);
    this.itemNameTextBox.Text = it.Name;
    this.supplierTextBox.Text = it.Supplier;
    this.unitCostTextBox.Text = it.UnitCost.ToString();
    this.nbRequiredTextBox.Text = it.NbRequired.ToString();
}

Thank you

Changing the text of the list box does not cause the selected index to change.

If you want listBox1_SelectedIndexChanged to fire, you will need to search the list box for the text you want to set it to, grab that index, then set the selectedIndex.

I'm assuming that's what you're trying to do.

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