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.

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

1

Wednesday, February 10th 2010, 9:51pm

JBGrid Click event

JBGrid Click event was not raised if clicked row is > 12 ???

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Thursday, February 11th 2010, 12:45pm

The following sample shows click events for rows greater than 12:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Option Explicit

Public Sub JBGrid1_Click()
   MsgBox "clicked!"
End Sub

Public Sub Form_Load()
   Dim row As Integer
   Dim col As Integer 
   Dim rowIndex As Integer = 2
   Dim columnIndex As Integer = 3
      
   JBGrid1.Cols = 4
   JBGrid1.Rows = 16
   JBGrid1.SelectionMode = flexSelectionFree
   JBGrid1.Editable= jbEditOnClick
   
   For row = 0 To JBGrid1.Rows - 1
      For col = 0 To JBGrid1.Cols - 1
         
         JBGrid1.DataMatrix(row, col) = row & ";" & col
         JBGrid1.DataMatrix(row, col).CanGetFocus = True
         JBGrid1.DataMatrix(row, col).Editable= True
         JBGrid1.DataMatrix(row, col).Enabled= True         
         JBGrid1.DataMatrix(row, col).TextAlign= fmTextAlignCenter
      Next col
   Next row
   
   JBGrid1.Refresh
   JBGrid1.Parent.clearSelection() 
   JBGrid1.Parent.changeSelection(rowIndex, columnIndex, False, False) 
   JBGrid1.DataMatrix(rowIndex, columnIndex).Parent.requestFocus
   JBGrid1.DataMatrix(rowIndex, columnIndex).SetFocus
   Me.Refresh
End Sub


Cheers

A1880

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Thursday, February 3rd 2011, 6:35pm

Hey everybody,

I can't get this to work! It seems like it doesn't matter whether row > 12 or < 12.
The Click() or DblClick() event is only fired for rows that have been within a visible range!
As soon as rows are affected by the vertical scroll pane there is no Click() event.

Try the above sample and set JBGrid1.Height = 90 !
On rows > 6 I don't get events!

I actually need the DblClick() event to be fired else I could just use the MouseUp() event but how could I catch the DblClick() over the JBGrid there or else?

Or maybe there is some way to go through JBGrid1.Parent.... that I haven't found yet?


Does anybody know how to work around this?

Is there any other post about this?


Dani

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Thursday, February 3rd 2011, 7:58pm

That's weird!

The MouseDown event gets triggered as expected:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Option Explicit

Public Sub JBGrid1_Click()
   Debug.Print "clicked!"
End Sub

Public Sub JBGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Debug.Print "Mouse Down " & JBGrid1.Parent.getSelectedRow & ";" & JBGrid1.Parent.getSelectedColumn 
End Sub

Public Sub Form_Load()
   Dim row As Integer
   Dim col As Integer 
   Dim rowIndex As Integer = 2
   Dim columnIndex As Integer = 3
      
   JBGrid1.Cols = 4
   JBGrid1.Rows = 16
   JBGrid1.RowHeightGlobal = 64
 
   JBGrid1.SelectionMode = flexSelectionFree
   JBGrid1.Editable= jbEditOnClick
   
   For row = 0 To JBGrid1.Rows - 1
      For col = 0 To JBGrid1.Cols - 1
         
         JBGrid1.DataMatrix(row, col) = row & ";" & col
         JBGrid1.DataMatrix(row, col).CanGetFocus = True
         JBGrid1.DataMatrix(row, col).Editable= True
         JBGrid1.DataMatrix(row, col).Enabled= True         
         JBGrid1.DataMatrix(row, col).TextAlign= fmTextAlignCenter
      Next col
   Next row
   
   JBGrid1.Refresh
   JBGrid1.Parent.clearSelection() 
   JBGrid1.Parent.changeSelection(rowIndex, columnIndex, False, False) 
   JBGrid1.DataMatrix(rowIndex, columnIndex).Parent.requestFocus
   JBGrid1.DataMatrix(rowIndex, columnIndex).SetFocus
   Me.Refresh
End Sub


The DoubleClick might be devoted to cell editing.

Greetings

A1880

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

5

Thursday, February 3rd 2011, 9:59pm

Click and dblClick on JBGrid and its header

Hey there A1880,

I kind of figured you would be there... ;)

Well I got a solution for now!

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Option Explicit

Implements java#awt#Event#MouseListener

Public Sub JBGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Debug.Print "Mouse Down " & JBGrid1.Parent.getSelectedRow & ";" & JBGrid1.Parent.getSelectedColumn 
End Sub

Public Sub Form_Load()
   Dim row As Integer
   Dim col As Integer 
   Dim rowIndex As Integer = 2
   Dim columnIndex As Integer = 3 

   JBGrid1.Parent.getTableHeader().addMouseListener(Me)  
   JBGrid1.Parent.addMouseListener(Me) 
   
   JBGrid1.Height =400   
   JBGrid1.Cols = 4
   JBGrid1.Rows = 16
   JBGrid1.RowHeightGlobal = 64
 
   JBGrid1.SelectionMode = flexSelectionFree
   JBGrid1.Editable= jbNotEditable
   
   For row = 0 To JBGrid1.Rows - 1
  	For col = 0 To JBGrid1.Cols - 1
     	If JBGrid1.Header(JBGrid1.Cols - 1)= "" Then  JBGrid1.Header(col) = col   
     	JBGrid1.DataMatrix(row, col) = row & ";" & col
     	JBGrid1.DataMatrix(row, col).CanGetFocus = True
     	JBGrid1.DataMatrix(row, col).Editable= True
     	JBGrid1.DataMatrix(row, col).Enabled= True     	
     	JBGrid1.DataMatrix(row, col).TextAlign= fmTextAlignCenter
  	Next col
   Next row
   
   JBGrid1.Refresh
   JBGrid1.Parent.clearSelection() 
   JBGrid1.Parent.changeSelection(rowIndex, columnIndex, False, False) 
   JBGrid1.DataMatrix(rowIndex, columnIndex).Parent.requestFocus
   JBGrid1.DataMatrix(rowIndex, columnIndex).SetFocus
   Me.Refresh
End Sub

Public Sub mouseClicked(arg2 As MouseEvent)
   ' capture a single click on the table header for sorting!
   If arg2.getY < JBGrid1.HeaderHeight  Then 
  	Debug.Print "header clicked " & JBGrid1.Header(JBGrid1.Parent.getColumnModel.getColumnIndexAtX(arg2.getX))
   End If
   ' capture dblclick on rows you have to scroll to!!
   If arg2.getClickCount = 2 Then Debug.Print "dblclicked " & JBGrid1.Parent.getSelectedRow & ";" & JBGrid1.Parent.getSelectedColumn
End Sub

Public Sub mousePressed(arg2 As MouseEvent)
End Sub

Public Sub mouseReleased(arg2 As MouseEvent)
End Sub

Public Sub mouseEntered(arg2 As MouseEvent)
End Sub

Public Sub mouseExited(arg2 As MouseEvent)
End Sub


It might not be very elegant but it works for me. I need the grid to be set to JBGrid1.Editable = jbNotEditable
Anything else does not work well with this solution !!
Also the MouseDown() event gets fired twice on the dblClick. But that could be worked around easyly.

happy that the .Parent (s) are there


Dani

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

6

Thursday, February 3rd 2011, 11:14pm

I just realized that depending on from where the mouse is moving towards the grid header you get different values for arg2.getY ! Aproaching from S you get values <= JBGrid1.HeaderHeight over the first row.

You can also use:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub mouseClicked(arg2 As MouseEvent)
   ' capture a single click on the table header for sorting!
'   If arg2.getY < JBGrid1.HeaderHeight  Then 
   If InStr(arg2.getComponent,"JTableHeader")  Then 
  	Debug.Print "header clicked " & JBGrid1.Header(JBGrid1.Parent.getColumnModel.getColumnIndexAtX(arg2.getX))
   End If
   ' capture dblclick on rows you have to scroll to!!
   If arg2.getClickCount = 2 Then Debug.Print "dblclicked " & JBGrid1.Parent.getSelectedRow & ";" & JBGrid1.Parent.getSelectedColumn
End Sub

I really don't like it very much since "JTableHeader" might change in a different versions or else!

to be continued I guess ....


Dani

emil

Beginner

  • "emil" is male

Posts: 7

Date of registration: Jul 7th 2011

Location: Staßfurt,Germany

  • Send private message

7

Monday, July 11th 2011, 3:11pm

I had simelar trouble: a click on a JBGrid row higher then 12 did not do anything. With your help and these lines it works:

Quoted

Source code

1
2
3
4
5
Implements java#awt#Event#MouseListener
Public Sub JBGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)    Debug.Print "Mouse Down " & JBGrid1.Parent.getSelectedRow & ";" & JBGrid1.Parent.getSelectedColumn  End Sub
and
   JBGrid1.SelectionMode = flexSelectionFree
JBGrid1.Editable= jbNotEditable   'und diese Zeile ist besonders fies...aber aus irgend einem buggy Grund wohl nötig
Thanks A1880 8)

"Die richtig fiesen Bugs kommen immer erst kurz vor Schluß zutage..."

Rate this thread
WoltLab Burning Board