Solved

controlling dbgrid

Posted on 1998-10-06
26
249 Views
Last Modified: 2013-12-25
hi..
just like to ask if there's any way to scroll 2 grid boxes simultaneously...i can get it to scroll down but not up..
0
Comment
Question by:wenchang
  • 10
  • 5
  • 3
  • +4
26 Comments
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1496730
I assume you are using the same record.. or atleast the key in the tables are the same..

you can just do

sub Grid1_RowColChange
  On error resume next
  Grid2.bookmark = Grid1.Bookmark
end sub


0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1496731
actually with some grids.. you may have to use this to change the rows..

sub Grid1_RowColChange
  On error resume next
  Grid2.Row = Grid1.Row
end sub
0
 

Author Comment

by:wenchang
ID: 1496732
i afraid your suggestion cannot work....
i'm using 2 different tables for the two grids....

0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1496733
I am confused.. you can get what to scroll down but not up.

You have two different tables.. and two different grids..

what do you want to happen in each grid
0
 

Author Comment

by:wenchang
ID: 1496734
i'll try to explain it more clearly.....
i have 2 grid boxes and 1 grid to display data from 1 table and the other grid to display data from another table..
if i use,
sub grid1_scroll()
   grid2.scroll 0, 1
end sub
i can get the 2 grids to scroll down together...but if i try to scroll up, grid2 will still be scrolling down....
hope it's more clear now...thanxx
0
 
LVL 1

Expert Comment

by:raygibbins
ID: 1496735
Try
   grid2.scroll 0, -1
to scroll up
I realise this will not solve your whole problem
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1496736
Add two timer1 to your form. Disable both timers (enabled = false) and set interval to 10.
Now add the following code.

Private Sub DBGrid1_Scroll(Cancel As Integer)
    Timer1.Enabled = True
End Sub

Private Sub DBGrid2_Scroll(Cancel As Integer)
    Timer2.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Timer1.Enabled = False
    DBGrid2.FirstRow = DBGrid1.FirstRow
End Sub

Private Sub Timer2_Timer()
    Timer2.Enabled = False
    DBGrid1.FirstRow = DBGrid2.FirstRow
End Sub
0
 

Author Comment

by:wenchang
ID: 1496737
oops...can't work....
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1496738
How so, can't work?? I don't understand
0
 

Author Comment

by:wenchang
ID: 1496739
the error message is "invalid bookmark"
0
 

Author Comment

by:wenchang
ID: 1496740
what's the timer for anyway???
0
 

Author Comment

by:wenchang
ID: 1496741
what's the timer for anyway???
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1496742
It works with the biblio database
try it without the timer.
the scroll event is send before the scroll is executed. that means that firstrow still contains the old value. You need the new value. That what the timer does. It allows the value to be updated.
Just try my solution in a simple project.
Add a data control, two timers and two grid controls to a form.
Bind the grids to the data control and see that it works.

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 3

Expert Comment

by:vbWhiz
ID: 1496743
You can solve this by using VB's built in scrollbar.

Add 2 scrollbars to your form.
add the following code to your form:

Private Sub VScroll1_Change()
DBGrid1.Scroll 0, VScroll1.Value - VScroll2.Value
DBGrid2.Scroll 0, VScroll1.Value - VScroll2.Value
VScroll2.Value = VScroll1.Value

End Sub

Private Sub VScroll2_Change()
DBGrid1.Scroll 0, VScroll2.Value - VScroll1.Value
DBGrid2.Scroll 0, VScroll2.Value - VScroll1.Value
VScroll1.Value = VScroll2.Value

End Sub


You can then align the scrollbars to the right of your grids &
turn off the internal scrollbar of the grids.

to have the scrollbar act more like the original you can also change the vScroll1.Max & the vScroll2.Max properties to equal the number of records in the grids.

I hope this works for you.
0
 

Expert Comment

by:varsha2
ID: 1496744
in the scroll event of one dbgrid, set the toprow properties of the two girds the same
here is an example

Private Sub dbGrid1_Scroll()
    dbGrid2.TopRow = dbGrid1.TopRow
End Sub

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1496745
toprow is not a property of dbgrid. He probably means firstrow and firstrow is only set after the scroll event.
0
 

Author Comment

by:wenchang
ID: 1496746
thanxx vbWhiz....
now how do i give u the points....
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1496747
vbWhiz, how do you now when to update the max-values of the scrollbar and what if you scroll using the cursor keys or home and end.
0
 

Author Comment

by:wenchang
ID: 1496748
wait a minute...i forgot to ask this..
i use rdoResultsets in my application and i sometimes gets this "maximun open cursors exceeded"...what does this means...

0
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1496749
I don't know about that error message specifically but there is some good info on cursors in the help file (RDO cursors) & (CursorDriver) you can modify the cursor style RDO uses using CursorDriver.

If your question is answered I can post my comments as an answer.
0
 

Author Comment

by:wenchang
ID: 1496750
ok....i'll go read up the help file...thanxx
think that's about it for this question.....u can post your comments as  an answer n i can give u the points..
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1496751
I made that once with 4 listboxes scrolling togheter. can't
find the code now, but i remember that i had a problem, and finally - i disabled 3 of the 4, so the user could scroll
only with One scrollbar. but they all moved simulatly . if u want - i can look for the code in the old HardDisk, but have to
put him in the machine first..........
0
 

Author Comment

by:wenchang
ID: 1496752
it's alright...vbWhiz has already solved my problem...thanxx anyway....
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1496753
does it work in a situation when the user scroll in one
scrollbar and stop scrollimg whitout letting the mouse button off ? i suppose u have a mismach at that moment.
0
 
LVL 3

Accepted Solution

by:
vbWhiz earned 200 total points
ID: 1496754
You can solve this by using VB's built in scrollbar.

Add 2 scrollbars to your form.
add the following code to your form:

Private Sub VScroll1_Change()
DBGrid1.Scroll 0, VScroll1.Value - VScroll2.Value
DBGrid2.Scroll 0, VScroll1.Value - VScroll2.Value
VScroll2.Value = VScroll1.Value

End Sub

Private Sub VScroll2_Change()
DBGrid1.Scroll 0, VScroll2.Value - VScroll1.Value
DBGrid2.Scroll 0, VScroll2.Value - VScroll1.Value
VScroll1.Value = VScroll2.Value

End Sub


You can then align the scrollbars to the right of your grids &
turn off the internal scrollbar of the grids.

to have the scrollbar act more like the original you can also change the vScroll1.Max & the vScroll2.Max properties to equal the number of records in the grids.

I hope this works for you.

0
 

Expert Comment

by:varsha2
ID: 1496755
try the following, this code is written assuming dbgrid1 will scroll responding to dbgrid2

'in the scroll event of dbgrid2, write the following code. This 'is to call or post the dbgrid1_scroll event, here we should 'post the dbgrid1 scroll event so that dbgrid2 is completely 'refreshed after the scroll
Private Sub DBGrid2_Scroll(Cancel As Integer)
     PostMessage DBGrid1.hwnd, 276, 0, 0
End Sub

'In the dbgrid1_scroll event write the following code
Private Sub DBGrid1_Scroll(Cancel As Integer)
    'set the row od dbgrid2 to 0
    DBGrid2.Row = 0
    'get the bookmark of the first row
    nextbookmark = DBGrid2.GetBookmark(DBGrid2.Row)
   
    'get number of rows in dbgrid1
    Data1.Recordset.MoveLast
    rows1 = Data1.Recordset.RecordCount
    Data1.Recordset.MoveFirst

    'get number of rows in dbgrid2
    Data2.Recordset.MoveLast
    rows2 = Data2.Recordset.RecordCount
    Data2.Recordset.MoveFirst
       
    'scroll to 1st row of dbgrid2
    For i = 1 To rows2
        DBGrid2.Scroll 0, -1
        DBGrid2.Row = 0
    Next
   
   'scroll to 1st row of dbgrid1
    For i = 1 To rows1
        DBGrid1.Scroll 0, -1
        DBGrid1.Row = 0
    Next
   
    ' for each row in dbgrid2 check if the current row is same   'as the stored bookmark, if not scroll both the grids
    For i = 1 To rows2
        DBGrid2.Row = 0
        If DBGrid2.GetBookmark(0) = nextbookmark Then
            Exit For
        Else
            DBGrid2.Scroll 0, 1
            DBGrid1.Scroll 0, 1
        End If
    Next
   
End Sub
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

758 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

23 Experts available now in Live!

Get 1:1 Help Now