You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

1

Thursday, November 22nd 2012, 12:25pm

JBGrid scoll to first and last row

Hi again,
is there someone that can help me?
I have a JBGrid with a scroll bar.
I also have a button called top and one called bottom.
How can i enable first row when i press TOP and how can i move to last when i press BOTTOM?

Thanks in advanced!

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

2

Thursday, November 22nd 2012, 3:48pm

RE: JBGrid scoll to first and last row

Short answer:

How can i enable first row when i press TOP

Jabaco Source

1
2
3
4
5
Public Sub Command1_Click()
   Dim v As javax#swing#JViewport = JBGrid1.getViewPort
   v.setViewPosition(New Point(0,0))
   JBGrid1.setViewport(v)
End Sub


Quoted

and how can i move to last when i press BOTTOM?

Jabaco Source

1
2
3
4
5
Public Sub Command2_Click()
   Dim v As javax#swing#JViewport = JBGrid1.getViewPort
   v.setViewPosition(New Point(0,99999))
   JBGrid1.setViewport(v)   
End Sub


Last one is only a dirty hack. I have had known how to find out the maximum. But currently, I don't remember. So I used a big number (9999) instead.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

3

Thursday, November 22nd 2012, 5:24pm

RE: RE: JBGrid scoll to first and last row

Quoted

Quoted

and how can i move to last when i press BOTTOM?

Jabaco Source

1
2
3
4
5
Public Sub Command2_Click()
   Dim v As javax#swing#JViewport = JBGrid1.getViewPort
   v.setViewPosition(New Point(0,99999))
   JBGrid1.setViewport(v)   
End Sub


Last one is only a dirty hack.
Here a better solution:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Public Sub Command2_Click()
   Dim v As javax#swing#JViewport = JBGrid1.getViewport
   Dim vpos As Single = v.getViewSize.getHeight-v.getViewRect.getHeight
   If vpos<0 Then
     v.setViewPosition(New Point(0,0))
   Else
     v.setViewPosition(New Point(0,vpos))
   End If
   JBGrid1.setViewport(v)   
End Sub

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

4

Thursday, November 22nd 2012, 5:31pm

And with this you can go to top and bottom, without changing the view position in X:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Public Sub Command1_Click()
   Dim v As javax#swing#JViewport = JBGrid1.getViewPort
   v.setViewPosition(New Point(v.getViewPosition.getX,0))
   JBGrid1.setViewport(v)
End Sub

Public Sub Command2_Click()
   Dim v As javax#swing#JViewport = JBGrid1.getViewport
   Dim vpos As Single = v.getViewSize.getHeight-v.getViewRect.getHeight
   If vpos<0 Then
     v.setViewPosition(New Point(v.getViewPosition.getX,0))
   Else
     v.setViewPosition(New Point(v.getViewPosition.getX,vpos))
   End If
   JBGrid1.setViewport(v)   
End Sub

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

5

Thursday, November 22nd 2012, 9:51pm

I will try you solutions.
Thank you very much for your help.
It is good that you are here, all of you, and help as.
Thanks again.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

6

Thursday, November 22nd 2012, 10:32pm

Hey there,

or try this

Jabaco Source

1
2
3
4
5
'scroll to last row
JBGrid1.Parent.changeSelection(JBGrid1.Rows - 1, 0, False, False)

'scroll to firs row
JBGrid1.Parent.changeSelection(0, 0, False, False)


If you don't want the rows to be selected
(JBGrid1.Rows, 0, False, False)
(-1, 0, False, False)


Dani

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

7

Friday, November 23rd 2012, 3:20pm

:thumbsup: :thumbsup: :thumbsup: thank you!!

Rate this thread
WoltLab Burning Board