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 Controls / October 2004

Tip: Looking for answers? Try searching our database.

Forcing Datagrid update of underlying data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JS - 27 Oct 2004 20:23 GMT
I have been encountering a problem reported by a number of people:
Data entered in a Windows Forms datagrid is not updated in the underlying
data
until the entry focus has been updated to the next row/column.
Specifically, my UI has a  DataGrid on a tab page, and I want the data
to get updated from the grid when switching between tabs
A few observations of my own:
I) The most common suggestion to handle this issue is to call the
currencymanger EndCurrentEdit method or the DataRowView.EndEdit method.
Comment: It seems to me that this will only remove the necessity of moving
to the next *Row*
of the grid. If you do not move to the next Column, then this does not force
the update.
II) I have found a workaround to this by creating an inherited
DataGridColumnStyle,
and exposing a public method "CommitChange" which called the protected
overridden "Commit". :

   Public Sub CommitChange(ByVal oCurMgr As CurrencyManager, ByVal
intRowNumber As Integer)
       me.Commit(oCurMgr, intRowNumber)
   End Sub

Then calling from the relevant form event:

Dim cm As CurrencyManager = _
CType(dgGrid1.BindingContext(dgGrid1.DataSource, dgGrid1.DataMemer)    ,
CurrencyManager)

Dim cd As CustomGridColumnStyle = _
CType(dgGrid1.TableStyles(0).GridColumnStyles(<UpdatingClumnNUmber>),
CustomGridColumnStyle)
cd.CommitChange(cm, dgRoster.CurrentCell.RowNumber)

This appears to work, though ,
    1)It seems tToo complicated to me.
    2) *DISCLAIMER* I am new to the whole .net/databinding thing, so I don't
know what
inherent bugs are in this code.

III) What I am currently using to solve this problem is putting the code

    dgDataGrid1.Select(0)

in the event handler for dgDataGrid1.Leave.

The final comment I have is that this kind of thing is exactly why  I have
always
avoided using grids for data entry, preferring instead read-only grids with
associated
discrete data entry controls. Unfortunately, my users insist on a grid in my
current project.

Jonathan Steinberg
BRCorp
jsteinberg@NOTBrcorp.com  (Not NOT for real address)

microsoft.public.dotnet.framework.windowsforms.controls
JS - 27 Oct 2004 21:07 GMT
I found antoher method that works - the endedit method of the datagrid will
force the update of the data, assuming you know which column your updatin (or
loop through them all). Im my case, I am using a custom grid colums style for
the editing column:

dgDataGrid1.EndEdit(dgDataGrid1.TableStyles(0).GridColumnStyles("colname"),
dgDataGrid1.CurrentCell.RowNumber, False)

> I have been encountering a problem reported by a number of people:
> Data entered in a Windows Forms datagrid is not updated in the underlying
[quoted text clipped - 54 lines]
>
> microsoft.public.dotnet.framework.windowsforms.controls
JS - 28 Oct 2004 18:17 GMT
Oops.
Putting
    dgDataGrid1.Select(0)

in the event handler for dgDataGrid1.Leave worked great when the grid was
the only control on the tab/form.
However I added another control to the tab teh grid was on, and now the grdi
will not relinquish focus. So this was not an overly brilliant  idea, I guess.

> I have been encountering a problem reported by a number of people:
> Data entered in a Windows Forms datagrid is not updated in the underlying
[quoted text clipped - 54 lines]
>
> microsoft.public.dotnet.framework.windowsforms.controls

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.