auto-update for datagridview bound with LINQ to DataSet RRS feed

  • Question

  • Hi,

    I have one application that is using a strongly typed DataSet. One thread that runs in the application keeps updating the tables of the DataSet. I want to use LINQ to DataSet to display data from two tables and I need this data to be updated in the data grid view control as the thread updates the underlying tables. Currently I am trying to get data from just one such table and display it in a data grid view and see that the data in the control is automatically updated, but I fail to do this.
    The pice of code I am using is:

    var my_list = from c in my_ds.my_table
                        select new {, Price = c.price};
    BindingSource bs = new BindingSource();
    bs.DataSource = my_cb_list;
    dataGridView1.DataSource = bs;
    This code above just gets my values and puts them in the grid view control, but the data is not updates.

    How can I achieve this auto-update for the data queried with LINQ and displayed in the grid view control?

    Thank you in advance!

    Sunday, April 5, 2009 8:12 PM


  • Hey Andrei,

    Have you considered just binding the table it self to the DataSource of the dataGridView. If you are using the designers you can even customize the columns that you want to display from the table.

    The data is never going to update correctly because of the Linq query that you are using. The select new keyword indicates that it will create a new object that is created on the fly. These objects are not connected to the DataTable that you created since they are essentially just copies.

    I would just use the designers in VS and drag drop the Strongly typed table that you have into the grid, or you can write code to select which columns you would like displayed on the grid.

    Here is a msdn topic that discusses how to customize in code the columns of a DataGridView

    Chris Robinson
    Program Manager - DataSet
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, April 6, 2009 8:21 PM