Datagrid binding refresh data

Nov 30, 2008 at 8:19 PM
I have a datagrid bound to a dataset:

dgData.DataContext = dsPaint.Destination.DefaultView;


When the dataset is refreshed, the datagrid does not show the new data.

How do you have the datagrid get updated?

Dec 1, 2008 at 9:21 AM
Hi,

The DataGrid should update automatically when bound to a DataTable. Can you provide a small complete example to illustrate your problem? How are you 'refreshing' your DataSet?

Regards,
Colin E.
--
http://wpfadventures.wordpress.com/ - my WPF blog
http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx - WPF DataGrid Practical Examples

Dec 2, 2008 at 3:33 AM
Hi Colin,

private

void Page_Loaded(object sender, RoutedEventArgs e)

 

{

            taDestination.FillPaint(dsPaint.Destination);

 

 

            dgData.DataContext = dsPaint.Destination.DefaultView;
            // or I have tried this            

 

            //dgData.ItemsSource = dsPaint.Destination.DefaultView;

 

            //and I have tried this one

            //dgData.DataSource = dsPaint.Destination.DefaultView;

}

and the dataset is refreshed in a timer

 

 

void tmrRefresh_Elapsed(object sender, ElapsedEventArgs e)

 

{

 

        tmrRefresh.Stop();

        taDestination.FillPaint(dsPaint.Destination);


        tmrRefresh.Start();

 

 

}


If I use the inragistics Datagrid this works fine....

Thanks,
Tom

 

Dec 2, 2008 at 8:57 AM
Hi,

You have to set your DataGrid's ItemsSource property to the DataView:

dgData.ItemsSource = dsPaint.Destination.DefaultView;

I am not sure what your FillPaint method actually does!

Sorry - maybe someone else here has some ideas.

Regards,
Colin E.
--
http://wpfadventures.wordpress.com/ - my WPF blog
http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx - WPF DataGrid Practical Examples



Dec 2, 2008 at 2:21 PM
Hi Colin,

I can see where the names are not helpful...

The program is tracking a conveyor system. On the conveyor are hung large heavy duty diesel engines. The engines get painted different colors depending on the brand. The FillPaint is filling a dataset of engines going into paint, and the taDestination is a TableAdapter. The engines are constantly moving and there is a separate program that updates the engines as they transition.

When the user sees the DataGrid, from time to time the data needs to be refreshed. The DataGrid is read only.

Thanks,

Tom