New records added to DataGridView aren't displayed
Posted
by Ross
on Stack Overflow
See other posts from Stack Overflow
or by Ross
Published on 2010-03-12T13:28:36Z
Indexed on
2010/03/12
13:37 UTC
Read the original article
Hit count: 160
winforms
|datagridview
I have a custom Order
class, groups of which are stored in List<Order>
and a DataGridView. I think the problem is in my implementation so here's how I'm using it:
In the form enclosing DataGridView
(as OrdersDataGrid
):
public partial class MainForm : Form
{
public static List<Order> Orders;
public MainForm()
{
// code to populate Orders with values, otherwise sets Orders to new List<Order>();
OrdersDataGrid.DataSource = Orders;
}
Then in another form that adds an Order:
// Save event
public void Save(object sender, EventArgs e) {
Order order = BuildOrder(); // method that constructs an order object from form data
MainForm.Orders.Add(order);
}
From what I can tell from the console this is added successfully. I thought the DataGrid would be updated automatically after this since Orders
has changed - is there something I'm missing?
The DataGrid accepts the class since it generates columns from the members.
© Stack Overflow or respective owner