Solved

DataGrid: Moving cursor to invisible row

Posted on 2004-09-08
9
224 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
Comment Utility
Assuming your datagrid is bound using ADO, then try this:

Adodc1.Recordset.AbsolutePosition = rownum
grd.SetFocus


S
0
 

Author Comment

by:vbdev04
Comment Utility

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
Comment Utility
I am not sure I follow you. What are you trying to achieve? What is the purpose of the loop?

S
0
 
LVL 19

Expert Comment

by:Shauli
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:vbdev04
Comment Utility

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
Comment Utility
'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
Comment Utility
Not sure though, let me know

S
0
 

Author Comment

by:vbdev04
Comment Utility

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
Comment Utility
Yeh, one problem solved, one more to go :)  as one wise programmer said once ...

Thanks for the points,

S

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now