Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm creating from c# Data-grid that contain Data-Table and fill it with data,then I have refresh button that when i'm clicking it i want to see the cells that their value has been change in another color(red for example). I'm pretty new in WPF so I don't really understand how to do it from the XML and I'm creating the tables from the code so I try to do it from the code too. tried everything and the cell background is not changing.
Thank's for everyone that will try to help :)

example of the code for creating the DataTable:

C#
string TID =selectedTab.Header.ToString().Split('~')[1]; // (TableID, Lvl)

            List<Tuple<string,string>> FieldList = API.getFieldsByTableID(TID); // {(Field_name,size in bits),...}

            DataGrid dg = new DataGrid();
                DataTable dt = new DataTable();

            string[] TableLevel = splitTID(TID); //TableLevel[0]=Table ;TableLevel[1]=Level;  

            string TableDump = API.GetRegs(TableLevel[0], TableLevel[1]);// Getting debug dump from simics

            #endregion

            #region *Fields_row*
            foreach (var item in FieldList)  // First line ,name of fields.
            {
                dc = new DataColumn(item.Item1, typeof(string));
                dt.Columns.Add(dc);
            }
            #endregion

            TableDump = TableDump.Split(':')[1]; // split to get just the dump
            int x = 0;
            int DumpLen = TableDump.Length; // dump length
            int EntrySize = int.Parse(API.GetEntrySize(TID)); // return entry size
            int NumOfBytes = round_bits_2_chars_amount(EntrySize);
            int count = 0;
            while (x < DumpLen)
            {
                count++;
                String str_Entry = BE_to_LE(TableDump.Substring(x, NumOfBytes));

                ulong Entry = ulong.Parse(str_Entry, System.Globalization.NumberStyles.HexNumber);

                DataRow dr = dt.NewRow();
                int row = 0;
                dr[row++] = count;
                foreach (var item in FieldList)
                {
                    int FieldLen = int.Parse(item.Item2);
                    ulong Mask =(ulong) ((1 << FieldLen) - 1);
                    ulong Value = Entry & Mask;
                    Entry = Entry >> FieldLen;
                    if (Properties.Settings.Default.IsHexadecimal)
                    {

                        dr[row] = "0x" + Value.ToString("X");
                    }
                    else
                    {
                        dr[row] =Value.ToString();
                    }

                    row += 1;
                }

                 dt.Rows.Add(dr);
                x += EntrySize;
            }
             dg.ItemsSource = new DataView(dt);
            selectedTab.Content = dg;
       }
    }


XAML :
<Window x:Name="MainWindow1" x:Class="Nagasaki.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Nagasaki"
        mc:Ignorable="d"
        Title="Nagasaki" Height="464.839" Width="1021.708" WindowStartupLocation="CenterScreen" WindowStyle="ThreeDBorderWindow" ResizeMode="CanResizeWithGrip">
    <Window.Resources>

    </Window.Resources>
    <Grid Margin="0,-3,3,5.6">
        <TabControl x:Name="tabControl" Margin="0,5,0,-4.2" HorizontalAlignment="Left" Width="198" SelectedIndex="1">
            <TabItem Header="FXP" Margin="99,-2,-148.2,0" FontFamily="Century Gothic" VerticalAlignment="Top" Height="17">
                <ListBox x:Name="listBox" Margin="10,7,15.8,15.4"/>
            </TabItem>
            <TabItem Header="ETM" Margin="-49.8,-3,0,0" FontFamily="Century Gothic" Foreground="#FF060000" BorderThickness="0" VerticalAlignment="Top" Height="19" HorizontalAlignment="Left" Width="100">
                <ListBox x:Name="ETM_listBox" Margin="7,10,7.8,11.4"/>
            </TabItem>
        </TabControl>
        <Grid x:Name="GridButton" Margin="0,0,23,8.4" RenderTransformOrigin="0.5,0.5" MouseDown="GridButton_MouseDown" Width="29" HorizontalAlignment="Right" Height="25" VerticalAlignment="Bottom">
            <Grid.Background>
                <ImageBrush ImageSource="Red_Arrow_Head_Right-5121.png"/>
            </Grid.Background>
        </Grid>
        <Button x:Name="button2" Content="Connect IA" Margin="0,0,71.6,7.8" Foreground="Black" BorderBrush="#FFB33434" BorderThickness="0" Click="button2_Click" Width="122" Height="25" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#FFBDC3CA"/>
        <Button x:Name="button" Content="Configuration" Margin="0,0,512.6,7.8" BorderThickness="0" Click="Configuration_Button_Click" RenderTransformOrigin="1.048,0.818" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="122" Background="#FFBDC3CA"/>
        <TabControl x:Name="DataTabControl" Margin="218,10,21.6,39.8" Background="#FFBCB3B3">

        </TabControl>
        <Button x:Name="CloseTabButton" Content="Close selected Tab" Margin="0,0,218.6,7.8" Background="#FFBDC3CA" BorderThickness="0" Click="button1_Click_1" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="122" Foreground="Black"/>
        <Button x:Name="CloseAllTabButton" Content="Close All Tabs" Margin="0,0,365.6,7.8" Background="#FFBDC3CA" BorderThickness="0" Height="25" Click="CloseAllTabButton_Click" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="122"/>
        <Button x:Name="RefreshButton" Content="Refresh table" Margin="0,0,659.6,8.4" BorderThickness="0" Click="Refresh_Button_Click" RenderTransformOrigin="1.048,0.818" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="122" Background="#FFBDC3CA"/>
    </Grid>
</Window>


What I have tried:

searched in google and did not find answer for my problem.
Posted
Updated 30-Sep-18 13:29pm
v2
Comments
Clifford Nelson 26-Sep-18 1:37am    
You should include your XAML.

A quick Google search[^] turned up this downloadable example that should do what you want: Flashing DataGrid Cell - How to do it properly[^]
 
Share this answer
 
Comments
Netanel Jerbi 26-Sep-18 9:20am    
I don't understand how he did it ( like I said in the post, I don't understand the XAML) if you can explain what should I do for make it work for me(or if you have some video or something to read about it can be great). thanks !!
Graeme_Grant 26-Sep-18 9:36am    
"I don't understand how he did it "... Marking down a solution to 1 out of 5 just because you don't understand a working solution won't win you help. We are not paid or obliged to help you, we do it because we want to help. Please show some respect.

To help you better understand the answer, he is using Data Binding (Microsoft Docs)[^] notifications to trigger the Animation (Microsoft Docs)[^] event. For that to work, you need to set the DataContext for the control and implement INotifyPropertyChanged (Microsoft Docs)[^] interface for data binding.
Clifford Nelson 30-Sep-18 14:50pm    
Until you understand XAML, you should not be working with WPF. The point of WPF is the XAML. This is a declarative language. If you do not want to deal with XAML go to WinForms
Graeme_Grant 30-Sep-18 19:01pm    
was your comment meant for me or the OP?
I would recommend that you use the CellStyle which can be associated with at . You can then use binding in the Style to change what attributes you need to DataGridColumn. If necessary you can use an IValueConverter in the Binding to convert to the Brush for the Background of in the CellStyle
 
Share this answer
 
Comments
Netanel Jerbi 26-Sep-18 2:00am    
can you give me some example please?
Obviously not you, the one asking the question...sorry for the confusion.
 
Share this answer
 
Comments
Graeme_Grant 1-Oct-18 2:35am    
Who are you replying to? I think that you're hitting the wrong buttons...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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