R
Rob Oldfield
I have a datagrid on a windows form that is tripping an error. The
details...
Windows form created in Visual Studio using VB with a data adapter, a
dataset and a dataview included. Load code looks pretty standard...
ClientsDS1.Clear()
ClientsDA.Fill(ClientsDS1)
ClientsDS1.Tables("Clients").Columns("Sel").ReadOnly=False
The form is basically just a datagrid, with the Sel column (which is
Boolean) populating a check box. The idea is that the user can just scroll
through the list and select whichever clients they're interested in.
(The datagrid is actually bound to a dataview which allows users to filter
the list of clients that they see - but I can't see that that has any
bearing on this problem.)
So the TableStyle of the datagrid is set at design time. The last column
being bound to this Sel boolean value.
Up to here everything works fine with no errors.
Next though I want to get rid of the annoying behaviour of the datagrid so
that if you click on the first checkbox to select the first client it just
selects the 'cell' with the first click and it's only the second click that
changes the value of the checkbox. So I stole some code from somewhere
else....
This is defined at the top of the class...
Private afterCurrentCellChanged As Boolean = False
and.this is in the datagrid click event...
Dim SendColNo As Integer = 2, dr As DataRow
Dim pt As Point = Me.ClientsDG.PointToClient(Control.MousePosition)
Dim hti As DataGrid.HitTestInfo = Me.ClientsDG.HitTest(pt)
If afterCurrentCellChanged AndAlso hti.Type = DataGrid.HitTestType.Cell Then
If hti.Column = SendColNo Then
Me.ClientsDG(hti.Row, hti.Column) = Not CBool(Me.ClientsDG(hti.Row,
hti.Column))
End If
End If
afterCurrentCellChanged = False
(the 2 is the column number of the boolean column i.e. it's the third column
in the datagrid)
....so now when you click the boolean column it immediately changes the state
of the check. But....
About one time in ten when I click a check box I get this...
Error when committing the row to the original data store
The ListManager's position must be equal to rowNum.
Parameter name: rowNum Do you want to correct the value?
I can't seem to trap this error. Even if I put the entire datagrid click
event in a try catch block then the error just comes up.
So... two questions...
Any ideas what's going and how to fix it?
Any different ways to get the datagrid to respond correctly to the first
click from a mouse?
Thanks.
details...
Windows form created in Visual Studio using VB with a data adapter, a
dataset and a dataview included. Load code looks pretty standard...
ClientsDS1.Clear()
ClientsDA.Fill(ClientsDS1)
ClientsDS1.Tables("Clients").Columns("Sel").ReadOnly=False
The form is basically just a datagrid, with the Sel column (which is
Boolean) populating a check box. The idea is that the user can just scroll
through the list and select whichever clients they're interested in.
(The datagrid is actually bound to a dataview which allows users to filter
the list of clients that they see - but I can't see that that has any
bearing on this problem.)
So the TableStyle of the datagrid is set at design time. The last column
being bound to this Sel boolean value.
Up to here everything works fine with no errors.
Next though I want to get rid of the annoying behaviour of the datagrid so
that if you click on the first checkbox to select the first client it just
selects the 'cell' with the first click and it's only the second click that
changes the value of the checkbox. So I stole some code from somewhere
else....
This is defined at the top of the class...
Private afterCurrentCellChanged As Boolean = False
and.this is in the datagrid click event...
Dim SendColNo As Integer = 2, dr As DataRow
Dim pt As Point = Me.ClientsDG.PointToClient(Control.MousePosition)
Dim hti As DataGrid.HitTestInfo = Me.ClientsDG.HitTest(pt)
If afterCurrentCellChanged AndAlso hti.Type = DataGrid.HitTestType.Cell Then
If hti.Column = SendColNo Then
Me.ClientsDG(hti.Row, hti.Column) = Not CBool(Me.ClientsDG(hti.Row,
hti.Column))
End If
End If
afterCurrentCellChanged = False
(the 2 is the column number of the boolean column i.e. it's the third column
in the datagrid)
....so now when you click the boolean column it immediately changes the state
of the check. But....
About one time in ten when I click a check box I get this...
Error when committing the row to the original data store
The ListManager's position must be equal to rowNum.
Parameter name: rowNum Do you want to correct the value?
I can't seem to trap this error. Even if I put the entire datagrid click
event in a try catch block then the error just comes up.
So... two questions...
Any ideas what's going and how to fix it?
Any different ways to get the datagrid to respond correctly to the first
click from a mouse?
Thanks.