Solved

DataGrid: Moving cursor to invisible row

Posted on 2004-09-08
9
228 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

809 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