Solved

DataGrid: Moving cursor to invisible row

Posted on 2004-09-08
9
227 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
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
A macro to Count the number of rows across all worksheets 3 96
to transfer string from C lanaguage to VBA 4 66
TT Auto Dashboard 13 92
Automatic Email Reminder 4 38
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

823 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