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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selected Position on DataGrid

Status
Not open for further replies.

Hira

Programmer
Nov 12, 2002
9
0
0
JP
Hi all

Now I am trying to get selected position where user clicks on DataGrid.
My test code is as follows.

Private Sub dgTrouble_Click()

Debug.Print "Row :", CStr(dgTrouble.Row)
Debug.Print "Col :", CStr(dgTrouble.Col)

End Sub

When I clicked certain cell on DataGrid for the first time,
I got a position data .
Then I clicked same cell , I got different position data.
But after this click, I got same position data at this cell.

I want to get same position data at first click.

Please give me some advices for resolving above problem.






 
Not quite sure what you are asking for.

Using DataGrid.Row does not give the actual record position, but the current grid row position for the visible rows only (or for the rows on the current page only - just in case the actual grid size is larger than the form).

So, if you click row 0, which happens to be the first record, and page down a couple of pages, and then click the top row on that page, you will also get row = 0.

If you want to return to a certain record, then use the BookMark property, eith of the grid, or of the underlying recordset:

varBkmk = DataGrid1.Bookmark

Page down a couple of pages.

Return to previous record:

DataGrid1.Bookmark = varBkmk


[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Hi CCLINT

Thank you for your quick reply.

My English is not good, so you might not be able
to understand what I want to question or to do.

I want to know which cell the user selects on the DataGrid.
So I am not interisted in actual record position.

I have not found good method to get cell's position user
selects yet.

I hope more advices.

Thanks !
 
The Row/Col properties return the correct positions for the current view only.

What I am saying is this:

DataGrid: the data grid displays all data on one page.

If the amount of data would fit on five pages, then when the user moves to page two, it really isn't page two they are moving to. But instead page one (the only page) is getting cleared and filled with the next set of data.

So Row 0 will return the same value on page 1 and page 2.

What you need to look at and work with is still the record position, in other words the recordset.

You can get coordinates using the recordset:

User clicks a cell

Position:

x = rsADO.AbsolutePosition - 1
y = rsADO(DataGrid1.Col) Or y = DataGrid1.Col

You can return to that position in the grid the same way:

rsADO.AbsolutePosition = x + 1
DataGrid1.Col = y

As opposed to the Flex grid, alot of users try to use the DataGrid's properties to control everything.

The DataGrid is a reflection of the recordset. Use the Recordset object to do everything with the data in the DataGrid. The DataGrid will automatically reflect any movements or changes done by the recordset.

Maybe you want to try using a HFlexGrid? There you have a cell matrix....but the HFlexGrid is not bound like the DataGrid is. [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Hi CCLINT
Thanks you very much !

Your explanation is very helpful for me.
I will study recordset object more.

Thanks
Hira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top