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开发者_JAVA百科 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.
精彩评论