Search code examples
c#wpf

Clearing MainGrid childs in C#


I want to remove "r", WPF user control, from my MainGrid. This code is for adding user control, the r, to Main Grid

   int a = 0;
   void patient_today() {

     foreach(var item in dbl.patientsToDay()) {

       if (a < 5) {
         // Add r per user reminder to main grid(User Control) & set design
         ReminderUR r = new ReminderUR();
         r.Text_ptName.Text = item.Patient.name;
         r.Text_Date.Text = item.Times + "  " + item.Dates;
         Grid.SetColumn(r, 0);
         Grid.SetRow(r, 1 + a); // add to next row
         Grid.SetColumnSpan(r, 3);
         MainGrid.Children.Add(r);
         a += 1;
       }

     }
   }

I tried use

MainGrid.childeren.remove(r)

but that did not work

To short, I want to refresh the information in my grid


Solution

  • All code worked correctly, the problem was at counting a.