The ListManager's position must be equal to rowNum

  • Thread starter Thread starter Rob Oldfield
  • Start date Start date
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.
 
Hi Rob,

I feel your pain as I was fighting hard with this error a couple of months
ago.

Here are some of my observations:

1. This error is somehow related to CheckBoxColumn
2. The message box you see is displayed from within the column style class
itself (you can check this with stack trace window). Seems that the column
style has an internal exception handler that traps exceptions and displays a
message box. If this is true, I'd wholeheardetly wish it should change in
the next version of .NET Framework.
3. In your case, it will be easier and quicker to develop your own checkbox
column, based on several custom column samples found here:

http://groups.google.com/[email protected]&rnum=8

(mind the line wraps)

P.S. I am racking my brain how data grid column styles themselves trap mouse
events, as this cannot be done in a custom column style. Probably there is
some private event?
 
Thanks for that Dmitriy. It's good to know that I'm not the only one that's
been beating my head against a wall over this one.

Sadly, I'm too much of a beginner at this to be able to convert the C#
example you've linked to VB. I don't suppose you know of anywhere with a VB
version of the same thing?

--
Rob Oldfield
www.realuk.co.uk


Dmitriy Lapshin said:
Hi Rob,

I feel your pain as I was fighting hard with this error a couple of months
ago.

Here are some of my observations:

1. This error is somehow related to CheckBoxColumn
2. The message box you see is displayed from within the column style class
itself (you can check this with stack trace window). Seems that the column
style has an internal exception handler that traps exceptions and displays a
message box. If this is true, I'd wholeheardetly wish it should change in
the next version of .NET Framework.
3. In your case, it will be easier and quicker to develop your own checkbox
column, based on several custom column samples found here:

http://groups.google.com/[email protected]&rnum=8

(mind the line wraps)

P.S. I am racking my brain how data grid column styles themselves trap mouse
events, as this cannot be done in a custom column style. Probably there is
some private event?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Rob Oldfield said:
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.
 
Rob,

There is a custom column style example in the MSDN Library and the example
is available in both C# and VB .NET. Please do a search for the
"DataGridColumnStyle Class" topic.
 
OK. I'll try that. Thanks.

--
Rob Oldfield
www.realuk.co.uk

Dmitriy Lapshin said:
Rob,

There is a custom column style example in the MSDN Library and the example
is available in both C# and VB .NET. Please do a search for the
"DataGridColumnStyle Class" topic.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Rob Oldfield said:
Thanks for that Dmitriy. It's good to know that I'm not the only one that's
been beating my head against a wall over this one.

Sadly, I'm too much of a beginner at this to be able to convert the C#
example you've linked to VB. I don't suppose you know of anywhere with
a
 
Just to follow this up if anyone else is looking for information on
this one...

I found that even using a custom checkbox column, I was still getting
the same error. One other piece of information: if the datagrid's
dock style is set to Full then you can always get the error by
clicking the last 'half visible' checkbox.

I took the case up with MS support and they have now confirmed that
it's a bug which is fixed in VS 2003. No word of whether they're
going to produce a fix for 2002.


Rob Oldfield said:
OK. I'll try that. Thanks.

--
Rob Oldfield
www.realuk.co.uk

Dmitriy Lapshin said:
Rob,

There is a custom column style example in the MSDN Library and the example
is available in both C# and VB .NET. Please do a search for the
"DataGridColumnStyle Class" topic.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Rob Oldfield said:
Thanks for that Dmitriy. It's good to know that I'm not the only one that's
been beating my head against a wall over this one.

Sadly, I'm too much of a beginner at this to be able to convert the C#
example you've linked to VB. I don't suppose you know of anywhere with
a
VB
version of the same thing?
 
thank you for your job... i was looking for that error....
i'll wait to install VS 2003.
If u know about fix write her..
bye Bye
Luca

Rob Oldfield said:
Just to follow this up if anyone else is looking for information on
this one...

I found that even using a custom checkbox column, I was still getting
the same error. One other piece of information: if the datagrid's
dock style is set to Full then you can always get the error by
clicking the last 'half visible' checkbox.

I took the case up with MS support and they have now confirmed that
it's a bug which is fixed in VS 2003. No word of whether they're
going to produce a fix for 2002.


"Rob Oldfield" <rob(an a in a circle)realuk.co.uk> wrote in message
OK. I'll try that. Thanks.

--
Rob Oldfield
www.realuk.co.uk

in message news:[email protected]...
Rob,

There is a custom column style example in the MSDN Library and the example
is available in both C# and VB .NET. Please do a search for the
"DataGridColumnStyle Class" topic.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Rob Oldfield" <rob(an a in a circle)realuk.co.uk> wrote in message
Thanks for that Dmitriy. It's good to know that I'm not the only
one
that's
been beating my head against a wall over this one.

Sadly, I'm too much of a beginner at this to be able to convert the C#
example you've linked to VB. I don't suppose you know of anywhere
with
a
VB
version of the same thing?
 
I installed VS 2003 and i have the same problem :-(

Can someone help me ?

Thank you.



Rob Oldfield said:
Just to follow this up if anyone else is looking for information on
this one...

I found that even using a custom checkbox column, I was still getting
the same error. One other piece of information: if the datagrid's
dock style is set to Full then you can always get the error by
clicking the last 'half visible' checkbox.

I took the case up with MS support and they have now confirmed that
it's a bug which is fixed in VS 2003. No word of whether they're
going to produce a fix for 2002.


"Rob Oldfield" <rob(an a in a circle)realuk.co.uk> wrote in message
OK. I'll try that. Thanks.

--
Rob Oldfield
www.realuk.co.uk

in message news:[email protected]...
Rob,

There is a custom column style example in the MSDN Library and the example
is available in both C# and VB .NET. Please do a search for the
"DataGridColumnStyle Class" topic.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Rob Oldfield" <rob(an a in a circle)realuk.co.uk> wrote in message
Thanks for that Dmitriy. It's good to know that I'm not the only
one
that's
been beating my head against a wall over this one.

Sadly, I'm too much of a beginner at this to be able to convert the C#
example you've linked to VB. I don't suppose you know of anywhere
with
a
VB
version of the same thing?
 
Hi Luca,

You're not the only one who has found the problem. I'm using
VS 2003 and I found the similar problem.

I can check/uncheck each cell as long as I don't sort the CheckboxColumn.
The error message will appear after I do the sorting and then check or
uncheck a cell.

In my case, I have to disable the sorting for the whole datagrid
which is not desired at all. Has anybody have a solution for this
one as well?

Yanna
 
Hmm. I'm afraid that I'm going to be very little help here. I was getting
the problem in VS 2002 even after I tried Dmitriy's idea of using a custom
column. Contacted MS support and they basically said that it was a bug in
2002 but fixed in 2003. I already had a copy of 2003 on order which turned
up a couple of days afterwards. Installed that and I no longer get the
error.

If you're getting this error in 2003 then all I can suggest is to go to
Microsoft. If it's a bug in 2002 then it'll almost certainly be a bug in
2003 (I would have thought). One question though - if you change the
docking for the datagrid, then do you still get the same error? I actually
noticed (in 2002) that if you have the dock style set to full and then click
on a 'half visible' check box at the bottom of the grid, then you always got
the error.

One other thing as well. The code I was using (originally stolen from MS)
fell over in another way in 2003. Clicking on that last 'half visible'
check box always created problems - the scroll event was kicking in to
reposition the row you click on and moving it before the click event fires.
I managed to get a solution for this one out of Microsoft as well, basically
to catch the cell clicked in the mouse down event instead....

Top of class...
Private row As Integer, column As Integer
Private hti As DataGrid.HitTestInfo
Private pt As Point


Private Sub ClientsDG_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ClientsDG.Click
Dim SendColNo As Integer = 2
If afterCurrentCellChanged AndAlso hti.Type = DataGrid.HitTestType.Cell Then
If column = SendColNo Then
Me.ClientsDG(row, SendColNo) = Not CBool(Me.ClientsDG(row, SendColNo))
End If
End If
afterCurrentCellChanged = False
End Sub

Private Sub ClientsDG_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ClientsDG.MouseDown
Dim myHitTest As System.Windows.Forms.DataGrid.HitTestInfo
myHitTest = ClientsDG.HitTest(e.X, e.Y)
row = myHitTest.Row
column = myHitTest.Column
pt = Me.ClientsDG.PointToClient(Control.MousePosition)
hti = Me.ClientsDG.HitTest(pt)
End Sub
 
I'm just in the process of closing the case with the MS bloke, and pointed
this thread out to him. His response was:

"I would suggest they contact us but first check their code, as with us
while initially this looked like a grid problem it was in-fact the code
behind.

In addition to this if they have installed 2003 with 2002 on the machine
are they "really" using the 2003 controls etc. I'm sure you noticed some of
the dialogues
prompting for certain things to be done in order to fully convert your
programs to 2003"
 
Back
Top