Datagridview DataError

timh

Well-known member
Joined
Nov 28, 2008
Messages
50
Programming Experience
Beginner
Hi,

I'm puzzled by this one, but hopefully someone can point me in the right direction.

It's a little hard to explain what is happening and I don't really know which bit of code (if any) is relevant to post.

My application consists of one main form and various others that open modally.

On the main form is a DGV, which is bound to a dataset, populated from an XML file. This displays up to 10 rows of data at one time and I think that is significant.

A couple of the other forms also include DGVs which are bound to the same source. The problem comes when I filter the data on the sub form and the filtered DGV contains less than the rows originally visible on the main form DGV. If whilst the filtered DGV is on screen I open Windows Explorer, a data error is raised relating to the DGV on the main form. It only seems to be when I try and open Windows Explorer, or My Computer. For some reason, at that point, the DGV on the main form tries to refresh itself with the filtered data and hits an error when it doesn't have sufficient data to fill the previously visible rows.

I hope that makes sense? It seems very strange and I have no idea why it happens only when I open Windows Explorer. If Windows Explorer is already open and I switch to that window, it doesn't throw the error.

Is it possible to suspend the DGV on the main form temporarily (so that it doesn't try to update itself) and then re-enable it when I switch back to the main form? That would solve the problem I think.

Thanks in advance for any suggestions.
 
How EXACTLY are you binding? It seems to me that you should be binding each grid to a different BindingSource so filtering one should have no impact on any other.

I suspect that I have committed some heinous crime in the way I bind my data, as I am basically picking things up as I go along...I have no training and work solely on a text book and tips I pick up from the internet.

Anyway...

The main source of data is an XML file, which I read into a dataset that I call "eventdataDS".

This contains several tables, the main one being "entrant".

Both DGVs are bound to this "entrant" table via a bindingsource object on each form, the datasource of each being the "entrant" table. Do I need to have two copies of the table in memory at one time? If so, how do I do that and how do I then reconcile them again? I feel I'm being really dim here.

The DGV on the main form is for the sake of argument, a basic list of my entrants. The second form that opens has a few select columns from that DGV and is where I rank the competitors. The filters allow me to view certain categories of entrant. The form also includes functions to print results tables.

Somehow, both DGVs need to link into the same underlying table.

Like I said, it is all working fine, right up to the point where I happened to open Explorer, whereupon the DGV on the main form then decided to filter itself to match the one on the results form and threw an error, because there weren't enough entrants in the filtered list to fill the visible rows. If I don't open Explorer, that doesn't happen. It doesn't do this if I open another application either. Nor does it do it if Explorer is already open and I "ALT-TAB" to switch to the Explorer application.

I'm struggling to explain this, as you can probably tell!
 
Last edited:
OK, think I might have sorted the problem. I have changed the bindingsource for the second DGV to a new dataview of the bindingsoure used by the DGV on the main form. That prevents the error, but means a bit of recoding elsewhere.

Thanks for making me think about what I was doing.
 
Back
Top