-3

I want something like this

foreach (TextBox tb in mainGrid.Children)
            {
                tb.Text = "";
            }

But this gives me all Elements. Thanks for help

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
Slinferno
  • 1
  • 1
  • 1
    It is winforms ? – puko Feb 24 '21 at 07:49
  • Then maingrid.Children only contains text boxes or their derivatives, otherwise you’d have an invalidCastException.. – Caius Jard Feb 24 '21 at 07:50
  • Why do you want this? Grids display data, they don't hold it. You don't mention what grid this is or even the application type (WinForms, WPF, WebForms, ASP.NET, MVC, Core, Blazor?) but in all cases, grids don't hold the data – Panagiotis Kanavos Feb 24 '21 at 07:50
  • Are you trying to reset an editable grid? You could "empty" the data it binds to, or replace the data source with an "empty" one. – Panagiotis Kanavos Feb 24 '21 at 07:52
  • Sorry, this is my first application in WPF. Would have been smart to mention that. I tried the whole thing with panels before but had problems with the view – Slinferno Feb 24 '21 at 07:54
  • It's often a good idea to tag your post with the language (which you did) and project type. Also define the type of `mainGrid`. – Rufus L Feb 24 '21 at 07:55
  • Would be a good idea, actually. Is my first post so please understand. Next time I know but then there are no more excuses. – Slinferno Feb 24 '21 at 07:59

1 Answers1

-1

I've done it with CheckBox, I let you check :

foreach(CheckBox x in this.GridEquipement.Children.Where(x=> x.GetType()==typeof(CheckBox)))
{
    x.IsVisible = true;         
}
Achon
  • 90
  • 4