?
Solved

DataGrid: Moving cursor to invisible row

Posted on 2004-09-08
9
Medium Priority
?
232 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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