Click here to Skip to main content
14,825,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Everybody,
I have a problem, which i tried to fixed but i couldnt. :( Can you help me? Thank you.
My project is used WPF. And my problem as follows:
I have a datagrid, which has a DataGridTextColumn changes color of a column according to status.I can display it. But this problem is when i changed status, refreshed datagrid. It didnt change color of this column.
I don't know how to express for you understand. :( castoffs, i want to change color of column in datagrid during running project.
Can you have me a solution? Thank you so much.

What I have tried:

I added data:
C#
private void add_data()
       {
            DataTable dt = new DataTable();
            ListItem_nv.Clear();
            dt = CMD_hengio.Show_hengio();
 foreach (DataRow Row in dt.Rows)
            {
                Item_hengio item= new Item_hengio();
                item.name_nv    = Row[1].ToString();
                item.ip_thuchien= Row[2].ToString();
                item.time       = ((DateTime)Row[3]).ToString("HH:mm:ss");// Row[3].ToString("HH:mm:ss"); 
                item.date_start = ((DateTime)Row[4]).ToString("dd/MM/yyyy");
                item.date_end   =((DateTime)Row[6]).ToString("dd/MM/yyyy");
                item.repeat     = Row[5].ToString();
                item.notes      = Row[9].ToString();
                item.status     = Row[8].ToString();
                item.tag_item = Row[0].ToString() + "*" + Row[7].ToString(); // add tag. 
                if (item.status == "Unfulfilled") item.Name_color = "Yellow";
                if (item.status == "Processing") item.Name_color = "Green";
                if (item.status == "Stop") item.Name_color = "Red";
                if (item.status == "Pause") item.Name_color = "YellowGreen";
                if (item.notes == "Error date")
                {
                    item.Color_Notes = "Red";
                }
                if (item.notes == "Error timer")
                {
                    item.Color_Notes = "Red";
                }
                else
                    item.Color_Notes = "#FF477067";
                ListItem_nv.Add(item); 
            }
            Datagrid.ItemsSource = ListItem_nv;
            ICollectionView view = CollectionViewSource.GetDefaultView(ListItem_nv);
            view.Refresh();
}

this is xaml:
XML

Posted
Updated 11-Oct-16 4:42am

1 solution

Try embedding your formatting in the markup
WPF XAML Conditional Formatting
   
Comments
nltd 15-Oct-16 2:42am
   
Thank Foothill so much for your solution. :)
I tried your solution and i could display color of cell. But i cant update refresh when change during running.
private void btn_stop_Click(object sender, RoutedEventArgs e)
{
add_data();
}
I need click second, datagrid changes color cell.
Can you have a solution for me? Thank you so much!
Regards,
NLTD
Foothill 17-Oct-16 9:24am
   
Does it give you any errors when the color change should take place or just does the background color just not change?

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