Linked DGVs

ballybeg

Member
Joined
Jul 28, 2011
Messages
20
Location
Canberra Australia
Programming Experience
10+
Hi there,

I have a simple question that I cannot find the answer to after hours of googling.

I have an object: RaceMeetings that has sub objects Races that has subobjects runners.

The object populates fine.


I have a form with three dgvs - meets, races, runners. In my main form I have the following:
VB.NET:
oMeetings = TOBApiCalls.fnLoadMeets()
  DataGridView1.DataSource = oMeetings
  DataGridView2.DataSource = oMeetings(0).Races
  DataGridView3.DataSource = oMeetings(0).Races(1).Runners

and all three populate fine.

I want a process where If I click on any row in the first dgv the second dgv uses the dgv1.row index as the data source as the the key for showing the data.

In the dgv.click event I added:

VB.NET:
DataGridView2.DataSource = oMeetings(DataGridView1.CurrentCell.RowIndex).Races

but I get an error:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

I can see that the oMeetings.currentcell.rowindex is a valid integer. What am I missing?

Thanks

Grantay
 
Doh -

I answered my own question and I am closing this by adding the answer - simply the declarations were contained on a button click even and the the oMeetings object was out of scope when run.

This is only a test harness and I would not normally take so many shortcuts. Shows it pays to do it the 'right' way from the start.

grantay
 
Back
Top