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

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Thu Jan 20 15:24:45 CST 2011


Hi John,

There is a Deactivate event for Form object.

Actually a System.Windows.Forms.Form has "more event types one can imagine"
- at least many of them are so weird for me - I have never used probably 95%
of .NET WinForms and controls events... :)

Try to KISS it now John.
At least on first pass.
What you have to do now is to create the main "meat" part of your app - all
forms.
You'd better generalize/make all the tricks later - it's so easy to make (if
needed) a generic form class inheriting from System.Windows.Forms.Form class
etc. and then use that class for all the relevant custom forms...

And you can't do it right this first time - it's more important to "get your
hands wet" with that stuff - the more you'll do mechanically now - the
better (IMO) - the easier and the quicker you'll get all that stuff
refactored later...

But as you're a seasoned professional with DB modeliing etc. - try to make
that part 99% right now.. - that will help a lot on the subsequent
refactoring steps...

<<<
> After browsing the internet and seeing what others 
are doing (lots of  pain expressed),
>>>
That are beginners very probably - there shouldn't be that much pain when
doing .NET System.Windows.Forms development. 
But when one is a beginner with WinForms - everything looks so complicated
because of the volume of information to get through, and because of the
project deadline stress...

Thank you.

--
Shamil
 
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: 20 ?????? 2011 ?. 23:39
To: Discussion concerning Visual Basic and related programming issues.
Subject: Re: [dba-VB] C# Grid: effectively and efficiently handle dirty

Interesting (and sticky) the form closing does not fire if the main
application is closed.

I added a saveEdits in the formclosing event (as you indicate) which works
if the user clicks the check box in the form that the edit is happening in.
IOW edit something then instead of moving to another line, they just close
the form.  In that case the closing event fires.  However that closing event
does not fire if the user closes the entire application.

Is there a form lostfocus?

John W. Colby
www.ColbyConsulting.com

On 1/20/2011 3:01 PM, Shamil Salakhetdinov wrote:
> 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"?
>




More information about the dba-VB mailing list