Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

force datagrid save?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan Crawford - 04 May 2005 17:11 GMT
Hi

I have a datgrid and when I click the toolbar or menu
which has a save action, the last change is ignored.
Is there anyway to force the datagrid to save
the current record?

thanks

jonathyan

Signature

===============
Jonathan Crawford
01273 440018
07799 068570
fax 01273 380221
jc@jcrawford.co.uk
===============

TT \(Tom Tempelaere\) - 05 May 2005 13:06 GMT
Hi Jonathan,

> Hi
>
[quoted text clipped - 5 lines]
> thanks
> jonathyan

Assuming that your data source is a DataTable (DataSource property of your
grid), call AcceptChanges on the DataTable. I haven't done this before, tell
me if this works.

Hope this helps,
Tom T.
Jonathan Crawford - 05 May 2005 15:00 GMT
Hi

On the menu click I did

myDataTable.accept changes
but that did no good.  I have some validation code which check
for null values and it failed to pick up the current line

I have tried currencymanager
and
databindingmanager.endcurrentedit
and
mydatagrid.endedit(nothing, mydatagrid.currentrowindex,nothing)

but have had zero luck

I have 4 fields, three of them are combo boxes and just want to ensure
none are empty when the xml file is saved, but to no avail.

If I transfer it to a command button it is fine, however the
whole design is based on menus.

thanks

Jonathan

"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
wrote in message news:O_nee.81851$bf4.5176458@phobos.telenet-ops.be...
> Hi Jonathan,
>
[quoted text clipped - 14 lines]
> Hope this helps,
> Tom T.
TT \(Tom Tempelaere\) - 05 May 2005 15:37 GMT
Jonathan,

> Hi
>
[quoted text clipped - 20 lines]
> thanks
> Jonathan

Have you tried ending the edit first, and then calling AcceptChanges?

I wonder why the command button works. I don't really know how the app is
set up. What is so different about way you do things for the button and the
menu?

Kind regards,
Tom T.
Brian Campbell - 10 Jun 2005 05:14 GMT
First, I'm new to this group and this is my first reply.

Second, I would like to know a better solution to this.  I have a solution
that I've used already, but its awkward.

I think what is happening is this:
When you edit cells in a row, they are buffered in the grid and don't get
saved to the DataRow object until the user navigates to another row (using
down arrow, up arrow, clicks on another row etc.).  If the user navigates to
a cell on the same row, the data just stays sitting in the grid.

So in the scenario where the user edits a cell and then selects a menu
command,  the data isn't in the DataRow yet.  So AcceptChanges isn't going to
do anything for us.

We can't rely on the user to move to another row on their last grid edit, so
how do we flush the data from the grid to the DataRow within code?  I've used
EndEdit to finish the cell, and then modified the CurrentCell property to
alter the current row up or down one from the current row.

This is a bit awkward. There should be a simple grid call to force the data
to be flushed.  In particular, how would I handle a one row display in the
grid (which could happen when you don't have an "add row" at the bottom due
to disabling of new rows).

Any better solutions would be appreciated.

"TT (Tom Tempelaere)" wrote:

> Hi Jonathan,
>
[quoted text clipped - 14 lines]
> Hope this helps,
> Tom T.
Al Christoph - 16 Aug 2005 03:50 GMT
Brian,
You have hit on one of the conundrums of design when allowing usrs to update
data base records. Different programs over the years have handled this
problem in different ways. In general, the convention seems to be that if
user makes a change and moves to a different row in the table (without
abandoning the change) then the change should be glued down without further
action required by the user.  That is user makes change, moves to new row,
and changes in previous row are saved.

The design problem has always been what if the user does not explicitly move
to another row but uses a menu or something else to pull focus away from the
editing process? (I'm being vague here because this really applies to both
the data grid view of the world and the classic form view of the world i.e.
MS Access Tables and Forms.) Different designers answer this question in
different ways. From what you have said, the datagrid abandons the changes
when focus leaves it but before the row has changed. This is entirely
consistent with the first do no harm school of thought on this subject. It
requires the user to "accept" his changes by always moving to another row.  
Different strokes for different folks.

I'm running into a different problem. The user can't type directly into the
grid. He uses a contextmenu to pick a date - yesterday, today, or the date in
a date time picker. The problem is two fold
1) 1f I don't do anything, then the value entered by the program is not
displayed until the user moves out of the cell. I want it displayed without
accepting it until the user moves to another row.
2) If I force the display by moving down and back up a row, everything is OK
UNLESS the user has sorted on the field that is being changed. You don't end
up back where you started under these circumstancces because the new value
will typically change the sort order UGH

More when I resolve these issues.
Signature

Regards,
Al Christoph
Senior Consultant and Proprietor
Three Bears Software, LLC
just right software @ just right prices  @3bears.biz

> First, I'm new to this group and this is my first reply.
>
[quoted text clipped - 43 lines]
> > Hope this helps,
> > Tom T.
Brian Campbell - 16 Aug 2005 17:11 GMT
For our user base, I don't think they will appreciate the "movement" to
another row requirement.  From their point of view, if they change a cell, it
should "take".  For example, if they change several rows, do a "Save" and
then come back and requery their data later, they will be disappointed if the
last row they edited didn't save.

I implemented a pick list chooser (a combo box) for a grid cell, and had
similar issues to your context menu issue.   For your two problems:
1) I presume you are using a DataGridTableStyle with DataGridColumnStyles.  
You should create a derived class from DataGridColumnStyles to use for your
date column.  Then you override the Commit method and use the
SetColumnValueAtRow method to update the grid.  I believe this technique
updates the grid, but not the underlying row until the user changes rows.
2) With sorting enabled, I found that I couldn't track the current row by
row number for the reason you stated.  I need to track the row so I could do
some inter-field validation after the row was finished being edited
(ironically, when the user changes row). I found that I needed to track the
current row by maintaining a reference to the Row object.

> Brian,
> You have hit on one of the conundrums of design when allowing usrs to update
[quoted text clipped - 28 lines]
>
> More when I resolve these issues.
Al Christoph - 17 Aug 2005 01:17 GMT
Thanks Brian for the clues to doing this right. By doing it right in this
context I mean something other than changing row currentcy to force the value
to stay glued down.

Here's what I ended up doing FWIW:

   Public Class dgcs
       Inherits DataGridTextBoxColumn
       Dim mNewValue As Object
       Dim isEditing As Boolean = False
       Property newValue() As Object
           Get
               Return mNewValue
           End Get
           Set(ByVal Value As Object)
               mNewValue = Value
               If Me.DataGridTableStyle.DataGrid.Parent Is Nothing Then
Exit Property
               Me.isEditing = True
               Dim dgt As DataGrid = Me.DataGridTableStyle.DataGrid
               Dim r As Integer = dgt.CurrentCell.RowNumber
               Dim cm As CurrencyManager = CType(dgt.Parent,
Form).BindingContext(dgt.DataSource)
               Me.Commit(cm, r)
           End Set
       End Property
       Protected Overrides Function Commit(ByVal dataSource As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
           If Me.isEditing Then
               Me.isEditing = False
               SetColumnValueAtRow(dataSource, rowNum, Me.mNewValue)
               Me.HideEditBox() ' THIS IS CRUCIAL
               Me.Invalidate()
           End If
           Commit = True
       End Function
   End Class

.....

   Private Sub putDate(ByVal d As Date)
       Dim curDgcs As dgcs =
Me.DataGrid1.TableStyles(0).GridColumnStyles(Me.DataGrid1.CurrentCell.ColumnNumber)
       curDgcs.newValue = d
   End Sub
   Private Sub miYesterday_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles miYesterday.Click
       Me.putDate(Today.AddDays(-1))
   End Sub
   Private Sub miToday_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles miToday.Click
       Me.putDate(Today)
   End Sub
Signature


Things I didn't show - the conversion of the relevant column styles from the
standard to my class. I did a no no and dis this in the windows generated
code.

The user right clicks in a cell, picks yesterday or today. The click event
causes the right newvalue to be set and the commit makes sure that it is
displayed.

By calling commit from the newValue setting property I get the kind of
automatic behavior we've been looking for here.

WHAT IS EVEN MORE MAGICAL is that for whatever reason if i have the column
as the sort, things reorder correctly without further intervention on my
part!!!!!

I'm going to modify this a bit further so that the sql gets fired off to
update the underlying tables. (This is NOT trivial in my particular case for
a variety of reasons:-)))

Now, if I could only figure out how to get the (*&^(*&^ EM_SETTABSTOPS to
work. (If you have a clue search for my posting of the other day on the
subject in these forums.)

Regards,
Al Christoph
Senior Consultant and Proprietor
Three Bears Software, LLC
just right software @ just right prices  @3bears.biz

> For our user base, I don't think they will appreciate the "movement" to
> another row requirement.  From their point of view, if they change a cell, it
[quoted text clipped - 47 lines]
> >
> > More when I resolve these issues.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.