Solved

DataGrid: Moving cursor to invisible row

Posted on 2004-09-08
9
229 Views
Last Modified: 2010-05-02
Hello,

In bound Datagrid, how do I move my cursor to an invisble row?

If the row is visble I get row=-1 when I set grd.row = rownum.

Thanks,
0
Comment
Question by:vbdev04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 500 total points
ID: 12009221
Assuming your datagrid is bound using ADO, then try this:

Adodc1.Recordset.AbsolutePosition = rownum
grd.SetFocus


S
0
 

Author Comment

by:vbdev04
ID: 12009410

It works for the first time but fails when repeated.

I assumed rownum = ado.recordset.absoluteposition
...

(set data in various rows)
Loop 4 times
    grd.row = grd.row + 1
    grd.Columns(2) = someData
Loop

ado.recordset.absoluteposition = rownum
grd.SetFocus
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12009488
I am not sure I follow you. What are you trying to achieve? What is the purpose of the loop?

S
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 19

Expert Comment

by:Shauli
ID: 12009633
Because if you loop among the rows, adding 1 each time you loop, then you don't need "recordset.absoluteposition" at all. The Grid scrolls automatically. And that left is to add the line: grd.SetFocus after the loop, and it will setfocus to the last line.

S
0
 

Author Comment

by:vbdev04
ID: 12009755

When user enters certain value in first column, program adds couple rows to the grid. Then the cursor has to go back to the original row it was at.

It works if,
I save grd.row and set it back to grd.row as long as the original row is stil visible. Fails if the saved row is now invisible.
    OR
Using your solution. But it fails the second time when the user causes the same condition (Now he is at the fifth row)





0
 
LVL 19

Expert Comment

by:Shauli
ID: 12010043
'In declaration area
Option Explicit
Dim OriginalRow As Variant

'in your sub
...

OriginalRow = grd.Row
...

(set data in various rows)
Loop 4 times
    grd.row = grd.row + 1
    grd.Columns(2) = someData
Loop

grd.Row = OriginalRow
grd.SetFocus

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12010066
Not sure though, let me know

S
0
 

Author Comment

by:vbdev04
ID: 12010209

Same result as ado.recordset...

From previous reply
I save grd.row and set it back to grd.row as long as the original row is stil visible. Fails if the saved row is now invisible.
    OR
Using your solution. But it fails the second time when the user causes the same condition (Now he is at the fifth row)

In first case using grd.row, rows get populated properly but the cursor doesnt move back to right place

When I use the absoluteposition, cursor moves back properly but second time, rows don't get populated properly. Function starts with grd.row = 4 (There are six visible rows so current row is the last but one). After grd.row = grd.row + 1, it becomes 3. On next row add, it becomes 4 then again 3 and 4. But at the end moves back to the correct row - though data in that row is messed up.

However, in cases when the data gets entered properly, grd.row = grd.row + 1 sets grd.row to 5

May be I should create a new question as you have solved the problem I had asked.
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12010271
Yeh, one problem solved, one more to go :)  as one wise programmer said once ...

Thanks for the points,

S

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question