wpf DataGrid - how to update a cell

Jul 15, 2009 at 7:23 PM

Hi

I am using the  the new wpf toolkit wpf dataGrid, an I wonder how can I update the value of a specific cell.

I am getting real time data (every 2 seconds) and I would like to update only the relevant cells with the new information.

Is there any other way to update data (real-time) efficiently into the wpf datagrid?

 

Please help :-)

Haim

Jul 15, 2009 at 7:49 PM

Unfortunately the makers of DataGrid have been absent of late.  Or at least their not answering me. In anycase they would probably tell you that the DataGrid is designed to work with bound objects.  Not accessing the cells directly.  Although no one told them that it isn't always practicaly to do so as I'm sure it is in your case.

What you need to do is like this.  From there you would alter the DataTable or dt in the example below and the grid would be automatically updated with your data.  This is probably nothing like what you wanted but I hope it helps.

                DataTable dt = new DataTable("test");
                DataRow dataRow;
                dt.Columns.Add("Item", typeof(string));
                dt.Columns.Add("0°", typeof(string));
                dt.Columns.Add("90°", typeof(string));
                dt.Columns.Add("180°", typeof(string));
                dt.Columns.Add("270°", typeof(string));
                
                dataRow = dt.NewRow();          
                dataRow[0] = String.Format("{0:0.000}", "label");
                dataRow[1] = String.Format("{0:0.000}", .090);
                dataRow[2] = String.Format("{0:0.000}", .95);
                dataRow[3] = String.Format("{0:0.000}", .100);
                dataRow[4] = String.Format("{0:0.000}", 1.1);
                dt.Rows.Add(dataRow);

                dataRow = dt.NewRow();
                dataRow[0] = String.Format("{0:0.000}", "label2");
                dataRow[1] = String.Format("{0:0.000}", .095);
                dataRow[2] = String.Format("{0:0.000}", .100);
                dataRow[3] = String.Format("{0:0.000}", .105);
                dataRow[4] = String.Format("{0:0.000}", 1.15);
                dt.Rows.Add(dataRow);

                dataGrid1.ItemsSource = dt.DefaultView;
                this.LayoutRoot.Children.Add(d[a]);  // This is a Grid or something

Jul 15, 2009 at 9:32 PM

Hi Martin,

Thanks for the prompt response. I did something similar, it just has performance issues because my real time updater is very busy.

this is the code:

_dataGrid.ItemsSource = dataMatrix;

CollectionViewSource.GetDefaultView(_dataGrid.ItemsSource).Refresh();

Right now I am using a timer in order to control my refresh frequency.

I hope that in the next release they are going to solve this problem.

Regards,

Haim