Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to change the forecolor from red to green when position is greater than 2..
my code is
xaml
<pre lang="xml"><my:DataGrid.Columns>
    <my:DataGridTemplateColumn Header="Icon" Width="50" IsReadOnly="True" >
        <my:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Image Source="{Binding Path=ImgPath}" Width="20" Height="20"/>
            </DataTemplate>
        </my:DataGridTemplateColumn.CellTemplate>
    </my:DataGridTemplateColumn>
    <my:DataGridTextColumn Header="Position"  Binding="{Binding Path=PO}"   />
    <my:DataGridTextColumn Header=" Name" Binding="{Binding Path=NA}"  />
    <my:DataGridTextColumn Header="Gender" Binding="{Binding Path=GE}"  />
     <my:DataGridTemplateColumn Header="Status" Width="50" IsReadOnly="True"  >
       <my:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Label Name="lbl" Content="{Binding Path=ST}" Foreground="Red" />
            </DataTemplate>
        </my:DataGridTemplateColumn.CellTemplate>
        </my:DataGridTemplateColumn>
        <my:DataGridTextColumn Header="Machine" Binding="{Binding Path=MA}"  />
</my:DataGrid.Columns>





xaml.cs
dt = new DataTable();
           dt.Columns.Add("PO");
           dt.Columns.Add("NA");
           dt.Columns.Add("GE");
           dt.Columns.Add("ST");
           dt.Columns.Add("MA");
           dt.Columns.Add("ImgPath", typeof(BitmapImage));

           DataRow dr = dt.NewRow();
           dr[0] = "1";
           dr[1] = "SAM";
           dr[2] = "Male";

           dr[3] = "Offline";
           dr[4] = "Comp123";
           dr[5] = new BitmapImage(new Uri("/MTDLL_TEACHER;component/Images/offline.png", UriKind.RelativeOrAbsolute));
           dt.Rows.Add(dr);

           dr = dt.NewRow();
           dr[0] = "2";
           dr[1] = "JOY";
           dr[2] = "Male";

           dr[3] = "Online";

           dr[4] = "Comp124";
           dr[5] = new BitmapImage(new Uri("/MTDLL_TEACHER;component/Images/online.png", UriKind.RelativeOrAbsolute));
           dt.Rows.Add(dr);

           dr = dt.NewRow();
           dr[0] = "3";
           dr[1] = "ADITYA";
           dr[2] = "Male";
           dr[3] = "Online";
           dr[4] = "Comp124";
           dr[5] = new BitmapImage(new Uri("/MTDLL_TEACHER;component/Images/play.png", UriKind.RelativeOrAbsolute));
           dt.Rows.Add(dr);

           dr = dt.NewRow();
           dr[0] = "4";
           dr[1] = "VISHAL";
           dr[2] = "Male";
           dr[3] = "Offline";
           dr[4] = "Comp124";
           dr[5] = new BitmapImage(new Uri("/MTDLL_TEACHER;component/Images/offline.png", UriKind.RelativeOrAbsolute));
           dt.Rows.Add(dr);

           dr = dt.NewRow();
           dr[0] = "5";
           dr[1] = "ANAY";
           dr[2] = "Male";
           dr[3] = "Online";
           dr[4] = "Comp124";
           dr[5] = new BitmapImage(new Uri("/MTDLL_TEACHER;component/Images/online.png", UriKind.RelativeOrAbsolute));
           dt.Rows.Add(dr);

           dataGrid1.ItemsSource = dt.DefaultView;
           dataGrid1.SelectedValuePath = "NA";

           DataRow[] result = dt.Select("PO >= 2");
           // AND Sex = 'm'");
           foreach (DataRow row in result)
           {
           here i want to change the color from red
to green

           }
Posted

1 solution

 
Share this answer
 
Comments
Sandeep Mewara 10-Jun-11 11:55am    
My 5!
vishal_h 11-Jun-11 1:51am    
Sir i am not getting what exactly i have to write here
foreach (DataRow row in result)
{
--- here i want to change the color from red
to green ----

}

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