Hi. The Complex databinding example (VS.NET 2005)_ "shows how to setup a winforms form using complex databinding to get a grid which is easy to edit due to the combo-boxes filled with related entity data." (Ref. Readme.txt)_
Some little instructions for that example:
- For adding, simply add a new row (* row) to the grid. No code is necessary.
- For updating, simply edit the row you want. No code is necessary.
- For deleting catch the UserDeletingRow event so you can add this entity to a collection to delete later. (you can delete right away if you want).
- For save the whole changes, simply add a button to persist (SaveMulti) the customer collection recursively. (Ref. Readme.txt).
Example of saving changes (only relevant code):
public partial class MainForm : Form
{
// move to here so other methos can use it
CustomerCollection customers;
OrderCollection ordersToDelete;
public MainForm()
{
...
// load all customers and bind them to the combobox
customers = new CustomerCollection();
...
// initialize orders to delete collection
ordersToDelete = new OrderCollection();
}
...
private void btnSaveChanges_Click(object sender, EventArgs e)
{
/// save all objects.
customers.SaveMulti(true);
/// delete objects marked to delete
ordersToDelete.DeleteMulti();
}
private void _ordersGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
OrderEntity orderSelected = ((OrderEntity)e.Row.DataBoundItem);
ordersToDelete.Add(orderSelected);
}
VSNet Help have a lot of information about DataGridView event handling. Good luck