views:

107

answers:

3

Im adding text TextBlock Text1,Text2,Text3 in Adddata() fucntion as follow.

if (i == 0)
{
    Text1.Text = tagname.AlarmTag;
}
if (i == 1)
{
    Text2.Text = tagname.AlarmTag;
}
if (i == 2)
{
    Text3.Text = tagname.AlarmTag;
}

Now in deletedata() i want to clear all contents in three textblock. How can i do that?because i cannot find Clear option.I want to clear text of three textblock at a time.

A: 

Set their text to an empty string?

paolot
A: 

To "clear" the data :

Text1.Text = String.Empty;
Text2.Text = String.Empty;
Text3.Text = String.Empty;
ZombieSheep
I can't do this.because i have selectionchnaged coding for that.So if i set null to thta textblock,when i mouseclick it will return the null string.
Anu
Where does NULL come into this? Your just setting the controls to display an empty string.
ZombieSheep
A: 

You could set the text of the textbox to an empty string.

Text1.Text = "";
Text2.Text = "";
Text3.Text = "";

You could also define your own extension method.

public static class ControlExtensions
{
    public static void Clear(this TextBox text)
    {
        text.Text = "";
    }
}

Then, just include a using directive for the namespace you defined your extension class in, and you can do:

Text1.Clear();
Text2.Clear();
Text3.Clear();
Sapph
Can u please explain more,which directive i have to include.Because im doing all this coding in main class only.(Just im moving Vc++ to C# so i dont know much about using etc.,)namespace WpfApp{ /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window {}My all funcitons...}
Anu
I would create a new file (ControlExtensions.cs) with that class inside of it. Make the namespace for this new file `WpfApp.Extensions`. In your original file (with your main class), add `using WpfApp.Extensions;` at the top to enable the new method.
Sapph