'C# clear TextBoxes when a button is clicked
On a C# project, I have a "SerialConnectorView.xaml" file that describes an interface with some components.
I added the "Clear all fields" button, called "DoClear" in the xaml. In the file "SerialConnectorsViewModel.cs" I added the "public void DoClear()" method that fires when I click the button. You can see the contents of DoClear() below.
Then I have a "SerialDataView.xaml" file that contains the TextBoxes that display the data.
SerialDataView.xaml and SerialConnectorView.xaml are loaded to the mainview.xaml. The main window looks like the following (there are other components loaded too that don't matter for this):
This is my DoClear method.
public void DoClear()
{
//Clear all the textBoxes
SerialDataView test = new SerialDataView();
test.DataViewParsed.Clear();
test.DataViewHex.Clear();
test.DataViewRaw.Clear();
MessageBox.Show("Still not able to clean the text fields damn it!");
}
The project runs and most things work properly. When I click the "Clear all fields" button the MessageBox shows up but the TextBoxes are not cleared. I don't have any experience with C# but I thought it wouldn't be that hard to clear some textboxes. Well, it's hard for me.
Any suggestions on how I can clear those textboxes on each press of the clear button on the file setup I described?
TIA.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|



