Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
Driving xamWebGrid programatically
posted

I need to display data in xamWebGrid without user input to show a queue of data through a process.  In looking at the forums, I found a thread where you suggested binding to an empty observable collection and just changing the collection.  That sounds perfect but I find almost no examples of INotifyCollectionChanged on the web or in books.  Certainly no simple ones for us rookies.

Would anyone have a really simple example around somewhere.  Maybe a two column grid showing First Name and Age.

That would solve one problem.  Then I will need to show item status by changing the color of rows.  So an item that is currently being processed might show in red.  There might be multiple rows of red items.  I need to touch the row color in a grid from code.

Parents
No Data
Reply
  • 21382
    posted

    1)  An  System.Collection.ObjectModel.ObservableCollection <YourType> would be a collection that already implements INotifyCollectionChanged, you wouldn't have to do any extra work.

    2)  Assuming your data implement INotifyPropertyChanged

     

     

     

     

          public class Person : INotifyPropertyChanged

          {

    private string _firstName;

     

                public string FirstName

                {

                      get

                      {

                            return this._firstName;

                      }

     

                      set

                      {

                            if (value != this._firstName)

                            {

                                  this._firstName = value;

                                  NotifyPropertyChanged("FirstName");

                            }

                      }

    }

     

                #region INotifyPropertyChanged members

     

                public event PropertyChangedEventHandler PropertyChanged;

     

                private void NotifyPropertyChanged(String info)

                {

                      if (PropertyChanged != null)

                      {

                            PropertyChanged(this, new PropertyChangedEventArgs(info));

                      }

                }

     

                #endregion //INotifyPropertyChanged members

    }

     

     

    What this will do will allow the grid to know when data has changed and fire the CellControlAttached event where you can change the style.

    Style s = new Style(typeof(CellControl));

    s.Setters.Add(new Setter(CellControl.BackgroundProperty, new SolidColorBrush(Colors.Red)));

    ((Row)e.Cell.Row).CellStyle = s;

     

Children
No Data