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.

  • 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;

     

  • 12631
    posted

    ObservableCollection<T> already implements the INotifyCollectionChanged interface so you should not have to do anything, the grid will automatically listen for the changes in that type of collection.

    Now if you want the grid to listen to changes within the objects *inside* of your collection, the objects in the collection need to implement the INotifyPropertyChanged interface.  I would start here:

    http://msdn.microsoft.com/en-us/library/ms229614.aspx

    A good blog post on conditional formatting (which is what it sounds like what your looking for to change the row colors) can be found here:

    http://blogs.infragistics.com/blogs/tony_lombardo/archive/2009/05/07/conditional-formatting-in-xamwebgrid.aspx

    Hope that helps.

    Devin