annoying problem filling a datagrid from an event

CyberDuke

Newcomer
Joined
Nov 11, 2005
Messages
4
Ok how can I fill out a data grid view from an event?

Upon receiving a serialized object across the network I raise an event and pass the deserialized object.

The event handler is on a form with a data grid view control
If I try to add a row (based on the data in the object) to this control or add a row to a table in the dataset that the control is bound to it just crashes with no errors
(It screws the screen up graphically and then freezes the whole app I can’t even catch this in a try catch statement)

I think it’s because I am trying to call the add row method asynchronously?
(since the method that raises the event is called from a method that is reading from a tcp client getstream.endread AsyncResult)

I get the exact same problem if I try to add the rows directly or if I try to add rows to a table in a dataset that’s bound to the control

And it’s not because it’s still sending because if in the event handler I add the ID of the object to a text box insted, I can see them all fill the textbox nicely and then stop at the end with no problems

I tried getting the event handler method to add the objects to an array list (in the form class) and then getting a timer control to add the items in the array list to the grid view one by one. This works but its unnecessarily slow and cumbersome.

Does anyone have any ideas?

PS. I am already guessing I am doing something stupid
 
YAY ok sorted it...

invoke is my new best friend

I was exploring why the timer thing worked and added a new thread that just looped around until the job was done invoking a method that tried to add rows to the data grid view from the first element of my array list.

it all seemed a bit "bodgie" at first but it works soooo sweet now, its v. cool

it will load 500+ objects into rows in the same time it takes to display the form so it does't even look like its loading.
 
Back
Top