System.Windows.Forms.DataGridView does not display data

Posted by Water Cooler v2 on Stack Overflow See other posts from Stack Overflow or by Water Cooler v2
Published on 2010-05-18T13:18:30Z Indexed on 2010/05/18 13:20 UTC
Read the original article Hit count: 239

Filed under:
|

All I am doing is a simple:

    // Both the methods, order.GetAllOrderItems() and order.GetOrderedItemsWhereBrandIs("foo")
    // return an IEnumerable<T> so the assignment to the DataSource property of the DataGridView
    // should be fine. The problem is in re-assigning the data source property.
    public void DisplayItems()
    {
        // The data appears if I have just this line.
        dgvOrderedItems.DataSource = order.GetAllOrderItems();

        dgvOrderedItems.DataSource = null;

        // This time the data grid does not take the new data source. Instead, because
        // of the null assignment in the previous statement, it displays no data at all.
        dgvOrderedItems.DataSource = order.GetOrderedItemsWhereBrandIs("Lenovo");
    }

My question is: is there a way to change the data source of a DataGridView control once it has been set? I am using C# 4.0 and Visual Studio 2010 for development.

© Stack Overflow or respective owner

Related posts about datagridview

Related posts about c#4.0