简体   繁体   中英

Cant clear textbox and richtextbox

I have a WPF project with a navigation window and a few pages. On one page I have a textbox and two richtextboxes. With a click on a button I want to clear the textbox and the two richtextboxes with the following code:

private void resetGUI()
{
    txtIndex.Clear();
    richEinzelTxtBemerkung.Document.Blocks.Clear();
    richTxtBemerkung.Document.Blocks.Clear();
    checkHauptzeichnung.IsChecked = false;
}

But it doesnt work. It seems that the clear method delete the value of the fields internal but in the GUI the value stays.

So what do you think might cause this problem?

you can do

txtIndex.Text = String.Empty;

or

txtIndex.Text = "";

Okey i found my mistake. I fill the Boxes again after clearing them. J found a mistake with a index count.

There is many way to clear Text of Rich Textbox.

1) richTextbox.Text="";

2) richTextbox.Text=string.Empty;

3) Declare one global variable like:

string emptyString="";

and assign to every taxtbox, richtextbox and variable which you want to clear

a) richTextbox.Text=emptyString; b) nameTextbox.Text=emptyString; c) name=emptyString;

Thanks.

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