[dba-VB] C# Grid: effectively and efficiently handle dirty

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Thu Jan 20 14:01:51 CST 2011


Hi John --

So you use VS2008 (at least) and you have a "datasheet form" - a bound
DataGridView with BindingNavigator bound to ADO.NET dataset etc.?
If yes - BindingNavigator has CurrentChanged event, which if fired as soon
as you move to the other grid's row.
When form is closing FormClosing event is fired:

private void shipperBindingSource_CurrentChanged(object sender, EventArgs e)
{
    saveEdits();
}

private void saveEdits()
{
    this.Validate();
    this.shipperBindingSource.EndEdit();
    this.tableAdapterManager.UpdateAll(this.northwindNETDataSet1);
}

private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
    DataRowView row = shipperBindingSource.Current as DataRowView;
    if (row.Row.RowState == DataRowState.Modified) saveEdits();
}

Thank you.

--
Shamil

P.S. I must note I rarely work with bound forms and ADO.NET datasets - just
my preference but they should be OK in your context of small "quick&dirty"
(first version) apps...
 
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: 20 ?????? 2011 ?. 20:52
To: VBA
Subject: [dba-VB] C# Grid: effectively and efficiently handle dirty

I am doing C# forms, bound to SQL Server.  I dragged and dropped the table
out onto the form and C# "installed" the grid as well as a record navigation
toolbar.

Now I am trying to make sure that data is saved.  I have discovered for
example that if you edit something and just close the form... no save.
Basically no save unless the save button is pressed.

Being the anal guy I am, this ain't good enough.  I don't want to save after
every cell edit, but I do want to save after every row edit or when the form
closes.  Even this is non-trivial.

After browsing the internet and seeing what others are doing (lots of pain
expressed), my strategy is to have a RowDirty set by the
CellContentsModified but to be honest, things just aren't working as
expected.  The row leave isn't fired if I sink the CellModified (or
something).  All I can see for sure is that, while one would expect the row
leave to fire if a row is left (makes sense to me) that isn't true and so
now I am left with trying to figure out what zany rules exist.

So here I am, hat in hand, asking the list "how do you do this"?

--
John W. Colby
www.ColbyConsulting.com




More information about the dba-VB mailing list