Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I have one datagird contains 1 to 99 numbers in silverlight 3 .net framework 4.0
i have to find a cell data according to passing parameter and have to mark or change the color of that number that number which present in data grid.

so i want to know How to traverse a datagrid row and coloumn? and How to compare datagrid cell content with user specified value
?
Posted

Hi,

You should not want to traverse the datagrid. What you need to do is create a structure containing your data, inclusive of the textcolor you need like:

class GridData : INotifyPropertyChanged
{
   public event PropertyChangedEventHandler PropertyChanged;

   private int _number;
   private SolidColorBrush _textColor;

   public int Number
   {
      get { return _number; }
      set
      {
         number = value;
         if (PropertyChanged != null)
         {
            PropertyChanged(this, new PropertyChangedEventArgs("Number"));
         }
      }

   public SolidColorBrush TextColor
   {
      get { return _textColor; }
      set
      {
         _textColor = value;
         if (PropertyChanged != null)
         {
            PropertyChanged(this, new PropertyChangedEventArgs("TextColor"));
      }
   }
}


Now, in your XAML, bind the Number property to the "Text" property of the textbox used in your grid columntemplate, and bind the TextColor property to the "Foreground" property of the same textbox.

Whenever you change the TextColor property from your dataclass to another color, the PropertyChanged event will inform the grid of the change and display the desired color. so, no need to traverse the grid itself, just manipulate the underlying data.

Hope this helps in any way...

Regards, Perry
 
Share this answer
 
You can also try using a converter [^]- though it may not be the fastest approach, it is a clean approach to change the cell background.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900