G
Guest
I have been developing WinForms apps in .NET for several years and have never
discovered a good solution to this newbish problem. I frequently encounter a
situation where I want to change the value of a control when the user changes
the value of some other control and both controls are bound to the same row
in a DataTable.
For example, say I have a combobox of statuses and a textbox for comments
but comments are not applicable for certain statuses. When the user selects
one of these statuses I want to set the text of the textbox to an empty
string. So I add a handler to the combobox's SelectedValueChanged event and
set the TextBox's Text property to an empty string.
Doing this seems to cause unpredictable behavior. Sometimes I get an empty
textbox but the combobox is changed back to its original value and other
times the textbox is not cleared. I assume one change gets pushed to the
dataset and triggers a refresh of the controls from the dataset but I'm not
really sure. I have worked around this by clearing the textbox when the
combobox loses focus but users are never happy with this solution. Having
encountered this problem again I thought I would see if anyone can tell me
the "right" way to do this.
discovered a good solution to this newbish problem. I frequently encounter a
situation where I want to change the value of a control when the user changes
the value of some other control and both controls are bound to the same row
in a DataTable.
For example, say I have a combobox of statuses and a textbox for comments
but comments are not applicable for certain statuses. When the user selects
one of these statuses I want to set the text of the textbox to an empty
string. So I add a handler to the combobox's SelectedValueChanged event and
set the TextBox's Text property to an empty string.
Doing this seems to cause unpredictable behavior. Sometimes I get an empty
textbox but the combobox is changed back to its original value and other
times the textbox is not cleared. I assume one change gets pushed to the
dataset and triggers a refresh of the controls from the dataset but I'm not
really sure. I have worked around this by clearing the textbox when the
combobox loses focus but users are never happy with this solution. Having
encountered this problem again I thought I would see if anyone can tell me
the "right" way to do this.