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

Grid ActiveRow

Status
Not open for further replies.

TheBlainer

Programmer
Aug 31, 2011
37
CA
Hi,

I have a little problem and it seems so simple that it doesn't work. I have a grid that has a Sql statement as RecordSource and the data returned inside my grid is fine.
I have a button on my form that need to interact with the grid. So I need the ActiveRow of the grid and for that I thought the property ActiveRow from the grid would work, but it gives me 0 all the times. Same case with the property RelativeRow.

So can anyone tell what is wrong with what I'm doing?
Thanks

TheBlainer
 
I understand what you're saying Mike and it makes sense, but it still gives me 0...
I found another solution, I put my sql statement in a cursor and I do a Select nameOfCursor after.
With that I can use RECNO() to have the row.

So thanks Mike for trying to help.

TheBlainer
 
Even if you have a recordsource of a table, the activerow of the grid positions in the record, the current row is the grids activerow.

Bye, Olaf.
 
Yes, using the record in the underlying cursor is a better solution. I was going to suggest that, but I wasn't sure how to get the alias of the cursor when you were using a SQL statement as the record source. But doing the SQL outside of the grid, and using the cursor as the record source, makes good sense.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
The alias of a Sql statement as RecordSource would most probably be "Query" Unless you sepcify "...INTO CURSOR curGrid" or something along those lines. You really gain more control not using this type of recordsource and doing the query or whatever code to generate a cursor before or at least in grid.init().

Bye, Olaf.
 
ActiveRow returns zero if the grid doesn't have the focus or when you access a row outside the grid display.
but try to access ActiveRow inside the grid.
here is an exemple :
put this code snipet

thisform.text1.value = thisform.mygrid.ActiveRow
in
mygrid.column1.text1.click()

it works

Regards

Hassan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top