开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜