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