'There was an error committing the row back to the data source. Index was out of range'
Do you wish to correct the value?
Another "feature" of the Windows Forms DataGrid that drove me nuts for some time yesterday. Roughly speaking my problem and solution is described here: RE: [aus-dotnet] DataGrid.CurrentRowIndex vs DataGrid.CurrentCell.RowNumber
My problem also seemed to have been caused by setting the DataSource to Nothing/null, which I had done to force a refresh of the grid. As a reminder to myself, this is a better way to refresh the grid:
CType(Me.BindingContext(myGrid.DataSource), CurrencyManager).Refresh()
Also, supposedly one should use the SetDataBinding method rather than setting the DataSource at runtime. I find that strange, as the DataSource property's set statement does almost exactly the same thing as the SetDataBinding method does:
Public Sub set_DataSource(ByVal value As Object) If (((Not value Is Nothing) AndAlso Not TypeOf value Is IList) AndAlso Not TypeOf value Is IListSource) Then Throw New Exception(SR.GetString("BadDataSourceForComplexBinding")) End If If ((Me.dataSource Is Nothing) OrElse Not Me.dataSource.Equals(value)) Then If (((value Is Nothing) OrElse (value Is Convert.DBNull)) AndAlso Not "".Equals(Me.DataMember)) Then Me.dataSource = Nothing Me.DataMember = "" Else Dim flag1 As Boolean If (Not value Is Nothing) Then Me.EnforceValidDataMember(value) End If Me.parentRows.Clear Me.originalState = Nothing Me.caption.BackButtonVisible = (flag1 = False) Me.caption.DownButtonActive = (flag1 = flag1) Me.caption.BackButtonActive = flag1 Me.caption.SetDownButtonDirection(Not Me.layout.ParentRowsVisible) Me.Set_ListManager(value, Me.DataMember, False) End If End If End Subvs.
Public Sub SetDataBinding(ByVal dataSource As Object, ByVal dataMember As String) Dim flag1 As Boolean Me.parentRows.Clear Me.originalState = Nothing Me.caption.BackButtonVisible = (flag1 = False) Me.caption.DownButtonActive = (flag1 = flag1) Me.caption.BackButtonActive = flag1 Me.caption.SetDownButtonDirection(Not Me.layout.ParentRowsVisible) Me.Set_ListManager(dataSource, dataMember, False) End Sub
Labels: rant
0 Comments:
Post a Comment
<< Home