ArgumentOutOfRangeException with Datagrid in PocketPC.is it a framework bug ?

G

Guest

H

this is the second time i post a question about the strange behaviour of datagrids in WindowsCF
Using VB.NET i display data of a dataset using a datagrid. From time to time i get an argumentOutOfRangeException in mscorlib, this exception is not cachable into a try and catch block and i can't find an error in my coding.
First time i got it was while trying to change the rowfilter property of the defaultView of my dataTable when the datatable is already set as the datasource of the datagrid. I began creating a new dataview with a different owfilter everytime i needed to change rowfilter, then assigning this new dataview to the datagrid. THis worked

Now when i want to delete a row from the datagrid, i use the delete() of the dataview BUT, in some cases this generates the abouve exception, namely when the datagrid has more than 2 columns and i cick randomly on different cells on different columns. After doing this stupid stick-ballet, i get the error. If i select the rows clicking on the same column, i get no error. Debugging is no help. If i use a breakpoint before the delete() line, comment this line and execute the deleting manually through the commandwindow, the deletion is ok and the dataview.count says i actually erased a row. i think the problem is in the datagrid itself
In the end, i solved this problem too: before deleting the line i set to nothing the datasource of the datagrid and after deleting i put back the dataview. But this behaviour is really stupid !

has some of you some explanation ? is this a bug of the datagrid ?
 
G

Guest

I got tired of this behaviour too and reluctantly adopted the same solution


----- Wentu wrote: ----

<snip
In the end, i solved this problem too: before deleting the line i set to nothing the datasource of the datagrid and after deleting i put back the dataview. But this behaviour is really stupid !
 
I

Ilya Tumanov [MS]

Unless you're using grid's CurrentRowIndex to delete rows directly from the
DataTable or from the DataView which is not bound to the grid, it should
work.

Changing filter/sort on a DataView which is already bound to a control is
also supported, but can only be done from UI thread.

Exception you could not catch would suggest you're doing something from
another thread (i.e. using asynchronous methods).
If so, you need to use Control.Invoke to delete rows and change
filters/sort on UI thread.

If this is not the case, please post a repro so I can investigate. Thanks.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Thread-Topic: ArgumentOutOfRangeException with Datagrid in PocketPC.is it a framework bug ?
thread-index: AcRDDIyaNQYk/udaSUWwoyJLDiyuRg==
X-WN-Post: microsoft.public.dotnet.framework.compactframework
From: "=?Utf-8?B?V2VudHU=?="
Subject: ArgumentOutOfRangeException with Datagrid in PocketPC.is it a framework bug ?
Date: Wed, 26 May 2004 03:31:05 -0700
Lines: 10
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.compactframework
Path: cpmsftngxa10.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:53957
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi

this is the second time i post a question about the strange behaviour of
datagrids in WindowsCF.
Using VB.NET i display data of a dataset using a datagrid. From time to
time i get an argumentOutOfRangeException in mscorlib, this exception is
not cachable into a try and catch block and i can't find an error in my
coding.
First time i got it was while trying to change the rowfilter property of
the defaultView of my dataTable when the datatable is already set as the
datasource of the datagrid. I began creating a new dataview with a
different owfilter everytime i needed to change rowfilter, then assigning
this new dataview to the datagrid. THis worked.

Now when i want to delete a row from the datagrid, i use the delete() of
the dataview BUT, in some cases this generates the abouve exception, namely
when the datagrid has more than 2 columns and i cick randomly on different
cells on different columns. After doing this stupid stick-ballet, i get the
error. If i select the rows clicking on the same column, i get no error.
Debugging is no help. If i use a breakpoint before the delete() line,
comment this line and execute the deleting manually through the
commandwindow, the deletion is ok and the dataview.count says i actually
erased a row. i think the problem is in the datagrid itself.
In the end, i solved this problem too: before deleting the line i set to
nothing the datasource of the datagrid and after deleting i put back the
dataview. But this behaviour is really stupid !!

has some of you some explanation ? is this a bug of the datagrid ?
 
Joined
Feb 15, 2006
Messages
1
Reaction score
0
Another workaround

Hi,

I ran into the same issue with RowFilter when I ... 1) scrolled a grid vertically a bit and 2) the result of the applied RowFilter contained fewer rows than my previous VScrollBar.Value.

Found some code here: http://forums.devbuzz.com/m_33085/mpage_1/key_/tm.htm#33085

I tested it with rowToSelect = 1 (also tried = 0) but still the error. So I tried:

Imports System.Reflection

Private Sub ScrollGridToTop()

Dim fi As FieldInfo = myDataGrid.GetType().GetField("m_sbVert", BindingFlags.NonPublic Or BindingFlags.GetField Or BindingFlags.Instance)

Dim vsb As VScrollBar = CType(fi.GetValue(myDataGrid), VScrollBar)

If Not (vsb Is Nothing) Then vsb.Value = vsb.Minimum

End Sub

I call it before applying RowFilter and have not gotten an ArgumentOutOfRangeException since.

Best regards,
Jonas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top