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

Grid shows another record as seleted after changing Index tag 1

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Hi,

I have a grid showing records from a cursor. All columns control sources are specified (columns from cursor). I have indexes on Barcode, Reference and Product Name. Initially Product Name order is selected and record pointer is on top.

Now, suppose the user selects the 5 record and then click on the Product Name header to toggle Ascending/Descending. But, after that is set, the grid shows the last record as selected. What I would like to do is, even after the Ascending/Descending is toggled or the user clicks on another column header to sort on that column, the earlier selected record should still be shown as selected.

I have the below code on column header Click event and the sorting is working. But, that disturbs the record shown as selected.

Code:
LOCAL lRecno
lRecno = RECNO('c_products')
IF ORDER() <> 'PRODUCT_NA'
     SET ORDER TO PRODUCT_NA
ELSE 
     IF DESCENDING()
	SET ORDER TO PRODUCT_NA
     ELSE
	SET ORDER TO PRODUCT_NA DESCENDING 
     ENDIF 	
ENDIF 	
thisform.reset_slno()
TRY
     GO lRecno IN c_products
CATCH
ENDTRY 	
thisform.grdList.Refresh()

The "thisform.reset_slno()" method has below code in it.

Code:
LOCAL lRec, lno
lRec = RECNO('c_products')
lno = 0
SELECT c_products
GO TOP 
SCAN 
     lno = lno + 1
     REPLACE slno WITH lno
ENDSCAN 
TRY 
     GO lRec IN c_products
CATCH
ENDTRY

Thanks in advance
Rajesh
 
Rajesh,

At a quick glance, I can't see anything wrong with your code. I can only suggest that you try temporarily removing the two instances of error-trapping (TRY / CATCH / ENDTRY), just to check that the GO .. IN are working correctly. Also try temporarily removing the call to reset_slno(), to see if that is where the problem lies.

Also, instead of refreshing the grid, you can just SetFocus to it. That might not be related to your problem, but it is more efficient.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Rajesh, another thing you could try is to run the code under the debugger, and observe the value of lRecno, immediately after you store it, and again immediately before you GO to it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Rajesh,

I think I can see what it is happening. The record pointer is being correctly reset, but when you do the refresh, it updates the grid with the new index order, and that puts the pointer to the last row. The solution is to move your [tt]GO lRecno IN c_products[/tt] to below the refresh.

Could you try that, and report back.

mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

Yeah! That could be a reason. I will try that and get back here soon.

Rajesh
 
Mike,

You got it right!
Moving the GO lRecno IN c_products to below the refresh did the trick!

I am wondering why I couldn't see that.
You're indeed something special ha ha...

Thank you very much for your time.
Rajesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top