3

I bind a list to DataGrid use the following code.

But, I have a problem to implement this scenario: When I select a row, I will check the row data and find the row. Then, check the Status Column cell, if the value is 'dex0D', I need to change the background to 'Red'.

I try to find the row, but, I have no idea to find the Status Column cell.


   object item = tegrd.SelectedItem;
            var currentRowIndex = tegrd.Items.IndexOf(item);
            DataGridRow row = tegrd.ItemContainerGenerator.ContainerFromIndex(currentRowIndex) as DataGridRow;



         <DataGrid x:Name="tegrd" Height="260" ItemsSource="{Binding}" VerticalAlignment="Top"  VirtualizingPanel.IsVirtualizing="False">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding YorktName}" Header="York" Width="150"/>
                <DataGridTextColumn Binding="{Binding CustomerName}" Header="Customer" Width="150"/>
                <DataGridTextColumn Binding="{Binding StatusDescription}" Header="Status" Width="150"/>
            </DataGrid.Columns>
        </DataGrid>


        List<Yorks> yorkslist = new List<Yorks>();
        public Datagridtestfindrow()
        {
            InitializeComponent();

            yorkslist.Add(new Yorks() { CustomerName = "name01", YorkName = "Pname001", StatusDescription = "dex0A" });
            yorkslist.Add(new Yorks() {  CustomerName = "name02", YorkName = "Pname002", StatusDescription = "dex0D" });

            yorkslist.Add(new Yorks() {  CustomerName = "name03", YorkName = "Pname003", StatusDescription = "dex0D" });
            tegrd.DataContext = modelist;
       }

    public class Yorks
    {
        public string YorkName { get; set; }
        public string CustomerName { get; set; }
        public string StatusDescription { get; set; }
    }

How can i implement this? thank you for your suggestions or ideas.

Yohann
  • 224
  • 1
  • 7

0 Answers0