DataGrid with DataSource that changes often causes Index out of bounds, Any ideas?

HairyCrab64
03-25-2006, 05:57 AM
Hi,

I am working on an application that has a few arrays that change fairly often. I want to display the array information to the form in a datagrid, because the formating is nice, and it keeps the individual feilds seperated.

The problem is, whenever I drag another window over the datagrid, it causes the datagrid paint method to be called, and if the background thread is modifying the array, (which it does roughly every 10 seconds or so), it causes an uncatchable index out of bounds exception, or a similar exception indicating that the indexes are incorrect.

I have put try catch's everywhere (including the datagrid.paint handler method) but the exception is never caught.

I am also using SyncLock everywhere the array is modified.

I am using multithreading, and when the array is modified, the method involks the thread on the parent form, and updates the datagrid datasouce.

A few things that I have tried to do (all unsucessfull)

1) I tried setting the method that modifies the array to do the following
a) make a copy of the array
b) modify the copy of the array
c) set the datagrid source to the second copy (not being modified)
d) on the next change, modify the first array
e) set the data source back to the first array
f) on the next change, make it on the copy
g) set the datasource back to the copy
etc etc.. I also had the datagrid.paint method detecting which array should be the datasource by means of a boolean (true means array1, false means array2) (or array0 and array1 for you hard core programers)

so in theory, the datasource's data is always static when it is set as the datasource, but still, the uncatchable exceptions appear.

another thing i tried...

2) I tried setting the datagrids paint method to synlock the original array, then make a copy of it, then set the copy as its datasource. still no good.



Any ideas on what i can do about this? I can impliment it in a list box, but the formatting is just not very good, and i am at a point where i need to get this part sorted out before i can put together the context menus for managing the objects in the array.

Anyone? http://www.xtremevbtalk.com/newthread.php?do=newthread&f=108#
Smilie http://www.xtremevbtalk.com/newthread.php?do=newthread&f=108#
Cool http://www.xtremevbtalk.com/newthread.php?do=newthread&f=108#
Smilie

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum