Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking 2 Datagrids

Status
Not open for further replies.

Rob2k2

Technical User
Oct 14, 2002
36
0
0
GB
I am trying to link 2 datagrids so that if you change row in one datagrid it automatically selects the corresponding row in the other one.

Each datagrid contains 2 seperate views of the same records so the number of rows is always the same and are in the same order.

The code i am currently using on the onclick datagrid event for table 1 is:-

Table2.Row = Table1.Row

Table 2

Table1.Row = Table2.Row

This works apart from when you are at a different vertical scroll position in each grid. In this case, it doesnt select the corresponding record.

Any ideas?

Thanks,

Rob
 
hi,

instead of reffering to the row number why don't u capture the value of the selected row and search in the other grid....
may be thru a SQL stmt.

[cheers]
Niraj
[noevil]
 
If the seperate views were built on seperate record sources, then use the Find method of each recordset, if there is a unique key to work with.

If you have cloned one recordset and have just hidden columns in the grid, then use the Bookmark property.

The Row property is actually the row count from the first visible row (currently visible row) downwards.

If you have 300 records, and 10 records are visible in the gid at a time, and grid1 is on the 200the record, then row 0 will be record 200 and row 10 will be reord 210 and row 99 will be record 300.

Another possiblity would be to set the second grids underlying recordset to the first record:

rsADO.MoveFirst

then set it's row to the first grid's rowbookmark:

DataGrid2.Row = DataGrid1.RowBookmark(DataGrid1.Row)

You may want to freeze the grid while performing this operation so the user's on slower machines do not see the record move to the first recor.

And, yet another method, is:
If the recordsets really contain the exact number of records, and in the exact same order, then try:

rsADO1.AbsolutePosition = rsADO2.AbsolutePosition

Replace rsADO1 with the name of the recordset object vaiable you are using, or the data control as in: Adodc1.Recordset.AbsolutePosition = Adodc2.Recordset.AbsolutePosition

The preferred method is using the recordset Find method on a unique key (or, if two fields together are usique, then use the Find method first on the first field, and then a second time using the second field).

 
Many thanks for your reply, will give it a go tonight.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top