Results 1 to 37 of 37

Thread: Checkbox & keydown [took some time but... RESOLVED!]

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Smile Checkbox & keydown [took some time but... RESOLVED!]

    Is it possible to have a checkbox' keydown event fire when one of the arrow keys is pressed? Or at least is there any way around this?
    Last edited by krtxmrtz; Sep 18th, 2006 at 10:53 AM.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown

    I just thought I could use the validate event... Would that make any difference?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown

    Quote Originally Posted by krtxmrtz
    I just thought I could use the validate event.
    No I can't, there's no way to know the code of the pressed key. I've tried to enable keypreview for the form and trap the arrow keys in the form's keydown event but it doesn't work.

    So how what can I do so that the arrow keys trigger some event when a checkbox has the focus?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Checkbox & keydown [as yet unserolved]

    I believe you'll need some API code for that. I'll post back when I find something

    EDIT: http://www.vbforums.com/showthread.p...t=key+trap+api

    Try:
    VB Code:
    1. Private Sub CheckBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = vbKeyUP or vbKeyDown or vbKeyLeft or vbKeyRight Then
    3.         'call your save function here
    4.     End If
    5. End Sub

    Just edited Shuja Ali's post for what I've gathered from your post. It might not exactly work, but it should be something similar to that i hope...
    Last edited by kregg; Sep 14th, 2006 at 08:22 AM.

  5. #5
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Checkbox & keydown [as yet unserolved]

    Could you do a msgbox and find out the ascii value for those keys and then use the keypress event to test for them?

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Me.KeyPreview = True
    4.    
    5. End Sub
    6. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    7.    
    8.     Select Case KeyCode
    9.         Case vbKeyLeft
    10.             MsgBox "left arrow"
    11.         Case vbKeyRight
    12.             MsgBox "right arror"
    13.     End Select
    14.  
    15. End Sub

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Checkbox & keydown [as yet unserolved]

    vbKeyLeft = 37
    vbKeyUp = 38
    vbKeyRight = 39
    vbKeyDown = 40
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: Checkbox & keydown [as yet unserolved]

    I am not sure what the problem you are having is, you were given code to test for key events and the corresponding codes for those keys. Is there something that we are overlooking??

    Thanks,

    D

  9. #9
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Checkbox & keydown [as yet unserolved]

    I understand the problem, but I'm not sure I know the solution.

    You could create a usercontrol that encapsulates a checkbox - I think you could make this work for you.

    Alternatively you can use the LostFocus event of the checkbox (but this doesn't let you know which key was pressed).
    This world is not my home. I'm just passing through.

  10. #10

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    All right, I'll try to explain what I want to do. It's related to my previous thread (this one)

    Please, take a moment to read my first post there and then try out the code attached to this post. If you click on the grid or use the enter or arrow keys, you'll see that the text in the target cell is selected (this I've done by means of a textbox), but in row 8 a checkbox appears. Click on any cell of row 8 and then try to navigate from there by means of the keyboard. The ener key works ok, but not so the arow keys. I'm trying to figure out the logic of it all...
    Attached Files Attached Files
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    The first thing I did was to add a form-level Watch on ActiveControl.Name, set to break when the value changed. I then made the following change

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.  
    3.     kee = KeyCode
    4.   [HL="#FFFF80"]  If KeyCode = vbKeyRight Then
    5.          chk1_KeyDown KeyCode, 0
    6.     End If[/HL]
    7. End Sub
    And I was happy when it worked. I then got rid of the watch and it no longer worked! I'm guessing that since the only thing that really happened was that the code was no longer pausing between the changing of the active control that a DoEvents (or two) will fix the problem, but I haven't been able to get it right yet.

  12. #12
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    Okay forget about the previous code. Just do

    VB Code:
    1. Private Sub setupcheckbox()
    2.     With grid
    3.         grid.CellBackColor = vbYellow
    4.         chk1.Visible = True
    5.         chk1.Move .Left + .CellLeft + 0.5 * (.CellWidth - chk1.Width), .Top + .CellTop
    6.         chk1.Value = grid.TextMatrix(grid.Row, grid.Col)
    7. '        chk1.SetFocus [HL="#FFFF80"]Commented[/HL]
    8.         chk1.ZOrder
    9.         oldcol = .Col
    10.         oldrow = .Row
    11.     End With
    12. End Sub

  13. #13

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by MartinLiss
    Okay forget about the previous code. Just do

    VB Code:
    1. Private Sub setupcheckbox()
    2.     With grid
    3.         grid.CellBackColor = vbYellow
    4.         chk1.Visible = True
    5.         chk1.Move .Left + .CellLeft + 0.5 * (.CellWidth - chk1.Width), .Top + .CellTop
    6.         chk1.Value = grid.TextMatrix(grid.Row, grid.Col)
    7. '        chk1.SetFocus [HL="#FFFF80"]Commented[/HL]
    8.         chk1.ZOrder
    9.         oldcol = .Col
    10.         oldrow = .Row
    11.     End With
    12. End Sub
    I'm not sure what this code's supposed to do... The idea is when the checkbox has the focus (i.e. when we are in row 8) then if I hit any of the arrow keys I want:
    1. The checkbox to become invisible
    2. The cell's text to be updated to 0 or 1 according to the checkbox value
    3. To select the text of the corresponding neighbour cell (therefore to update the textbox and make it visible)
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    In testing this I found another problem. If you use the right arrow to "tab" in the checkbox row and you go from column 8 to column 9, that triggers the grid_Scroll sub which calls the setuptextbox sub which shows the original value of the grid cell in row 8, column 9.

  15. #15
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by krtxmrtz
    3. To select the text of the corresponding neighbour cell (therefore to update the textbox and make it visible)
    Please describe what you mean by that.

  16. #16

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by MartinLiss
    In testing this I found another problem. If you use the right arrow to "tab" in the checkbox row and you go from column 8 to column 9, that triggers the grid_Scroll sub which calls the setuptextbox sub which shows the original value of the grid cell in row 8, column 9.
    Yes, I thought I would deal with the scroll event after the current problem had been fixed.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  17. #17

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by MartinLiss
    Please describe what you mean by that.
    See the attached image.
    Attached Images Attached Images  
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  18. #18
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Checkbox & keydown [as yet unserolved]

    as the arrow keys ( and tab) are system level keys, they are not returned in the keydow, keyup or keypress events of a form or any control on the form, so i am guessing you would have to use a system wide hook to catch them

    only other option i can see is to catch the event they cause, like the getfocus of whatever is next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  19. #19

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by westconn1
    as the arrow keys ( and tab) are system level keys, they are not returned in the keydow, keyup or keypress events of a form or any control on the form...
    I agree about the tab key but the arrow keys do trigger the keydown/keyup events. You can test this: just place a few common contols on a form, set breakpoints in the respective keydown events and then hit the arrow keys.

    However they just don't respond in the demo project I'm working on, maybe because the checkbox is sitting on a grid or maybe because the code has some flaws.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  20. #20
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    I think the attached does what you want. I had to hook the windows messages for the chekbox to do it so while the msghook dll that I used to do that claims that there aren't the "normal" problems with subclassing, always make sure when testing to end the app normally otherwise VB might crash.
    Attached Files Attached Files

  21. #21

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by MartinLiss
    I think the attached does what you want. I had to hook the windows messages for the chekbox to do it so while the msghook dll that I used to do that claims that there aren't the "normal" problems with subclassing, always make sure when testing to end the app normally otherwise VB might crash.
    Thanks Marty, I have yet to study the code and the readme file about the dll. One thing that doesn't work though is the right and left arrow keys when I'm in the checkbox. Could it be some minor fine tuning that I'm not aware of?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  22. #22
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by krtxmrtz
    ...One thing that doesn't work though is the right and left arrow keys when I'm in the checkbox. Could it be some minor fine tuning that I'm not aware of?
    I don't understand. If, for example, I go to a cell in the check box row that is currently zero, and check it and then use either the left or right arrow, the previously zero cell will show one. Isn't that what you want?

  23. #23

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by MartinLiss
    I don't understand. If, for example, I go to a cell in the check box row that is currently zero, and check it and then use either the left or right arrow, the previously zero cell will show one. Isn't that what you want?
    OK but when I leave the cell with the checkbox, I want to go up/down if I hit the up/down arrow keys, but the right/left arrow keys should take me to the right/left neighbouring cells, which don't: left & right arrow keys work exactly as the up & down arrows.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  24. #24
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    Here is an example of what happens when I run the program. Please try and tell me exactly what is not correct.

    Row 7: 387 190 631
    Row 8: _1_ _0_ _1_
    Row 9: 190 267 316

    I click the zero in column 2 and check the checkbox. I then use the up arrow and the 0 changes to a one and 190 is highlighted.

    I go back and click the same checkbox cell and now uncheck it. I then use the down arrow and the 1 changes to a 0 and the 267 is highlighted

    I go back to the same cell and check it. I the use the left arrow and the 0 changes to a 1 and the 1 in col 1 row 8 is highlighted.

    I go back to the same cell and uncheck it. I use the right arrow and the 1 changes to a 0 and the 1 in col 3 row 8 is highlighted.

  25. #25

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by MartinLiss
    Row 7: 387 190 631
    Row 8: _1_ _0_ _1_
    Row 9: 190 267 316
    Don't click on row 8: click for example on '190' in row 7, now arrow down to take you to the 0 (non-checked checkbox) of row 8 and now type left or right arrow. It goes down or up rather than left or right.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  26. #26
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Checkbox & keydown [as yet unserolved]

    I don't understand why the other doesn't work but try this.

    VB Code:
    1. Private Sub IMsgHookEvents_BeforeMessage(ByVal obj As MsgHookSvr.MsgHook, uMsg As Long, wParam As Long, lParam As Long, ReturnValue As Long, Cancel As Boolean)
    2.     ' in this particular case, it isn't really necessary to test for
    3.     ' hWnd, because we are subclassing only the chk1
    4.     If obj.hWnd = chk1.hWnd Then
    5.         Select Case uMsg
    6.             Case WM_KILLFOCUS
    7.                 chk1.Visible = False
    8.                 If GetAsyncKeyState(vbKeyLeft) Then
    9.                     chk1_KeyDown vbKeyLeft, 0
    10.                 ElseIf GetAsyncKeyState(vbKeyRight) Then
    11.                     chk1_KeyDown vbKeyRight, 0
    12.                 ElseIf GetAsyncKeyState(vbKeyUp) Then
    13.                     chk1_KeyDown vbKeyUp, 0
    14.                 ElseIf GetAsyncKeyState(vbKeyDown) Then
    15.                     chk1_KeyDown vbKeyDown, 0
    16.                 End If
    17.         End Select
    18.     End If
    19. End Sub

  27. #27

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by MartinLiss
    I don't understand why the other doesn't work but try this.
    No, this one isn't working either. It behaves somewhat erratically. The right and left arrow keys now work correctly for the checkbox row, they move you to the next cell to the right or left, but the checkbox should now be visible on the current cell and isn't.

    Also, if you navigate by means of the up or down arrow keys or the retunr key, sometimes you see strange things like moving one column to the left after typing return, moving one cell up after typing arrow down, etc. Also the background colour is not always updated.

    Well, I have printed the dll guide and your code and will try to study it and see what can do about this.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  28. #28
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Checkbox & keydown [as yet unserolved]

    Try this - the magic row is #4 and space will check the checkbox
    VB Code:
    1. Private Sub Check1_Click()
    2.     MSFlexGrid1.SetFocus
    3. End Sub
    4.  
    5. Private Sub Form_Load()
    6.     Check1.Visible = False
    7. End Sub
    8.  
    9. Private Sub MSFlexGrid1_EnterCell()
    10.     With MSFlexGrid1
    11.         If .Row = 4 Then
    12.             Check1.Left = .Left + .ColPos(.Col) + (.ColWidth(.Col) - Check1.Width) \ 2
    13.             Check1.Top = .Top + .RowPos(.Row) + (.RowHeight(.Row) - Check1.Height) \ 2
    14.             Check1.Value = Val(.TextMatrix(.Row, .Col))
    15.             Check1.Visible = True
    16.         End If
    17.     End With
    18. End Sub
    19.  
    20. Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    21.     If MSFlexGrid1.Row = 4 Then
    22.         If KeyAscii = 32 Then Check1.Value = Abs(Not CBool(Check1.Value))
    23.     End If
    24. End Sub
    25.  
    26. Private Sub MSFlexGrid1_LeaveCell()
    27.     With MSFlexGrid1
    28.         If .Row = 4 Then
    29.             .TextMatrix(.Row, .Col) = Check1.Value
    30.             Check1.Visible = False
    31.         End If
    32.     End With
    33. End Sub
    Edit: it also needs this Sub (attachment updated):
    VB Code:
    1. Private Sub MSFlexGrid1_Scroll()
    2.     With MSFlexGrid1
    3.         If Not (.RowIsVisible(.Row) And .ColIsVisible(.Col)) Then
    4.             Check1.Visible = False
    5.         Else[B]If .Row = 4 Then[/B]
    6.             Check1.Left = .Left + .ColPos(.Col) + (.ColWidth(.Col) - Check1.Width) \ 2
    7.             Check1.Top = .Top + .RowPos(.Row) + (.RowHeight(.Row) - Check1.Height) \ 2
    8.             Check1.Visible = True
    9.         End If
    10.     End With
    11. End Sub
    Edit2: another slight change to code (in bold above) - attachment not updated
    Attached Files Attached Files

  29. #29

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by bushmobile
    Try this - the magic row is #4 and space will check the checkbox
    It works, but the original project included a textbox to provide the selstart and sellength properties not available for the grid's cells. This makes it more difficult to fine tune it.
    At the moment I have so much feedback from you guys that I've got to put on the thinking cap and sit for a while in front of the printed code.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  30. #30
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Checkbox & keydown [as yet unserolved]

    Hey Presto! Textbox and Checkbox combined

    Attached Files Attached Files

  31. #31

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by bushmobile
    Hey Presto! Textbox and Checkbox combined
    Hey, that's great! Just one more detail's left to deal with, At the risk of messing around somewhat, I'd like the checkbox (and/or the cell it's on) to display a yellow background as well. Is that possible?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  32. #32
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Checkbox & keydown [as yet unserolved]

    umm, adding
    VB Code:
    1. ' In SetUpCheckBox()
    2.         .CellBackColor = vbYellow
    3.  
    4. ' In MSFlexGrid1_LeaveCell (under first If condition)
    5.             .CellBackColor = vbWhite
    should do it

  33. #33

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by bushmobile
    umm, adding
    VB Code:
    1. ' In SetUpCheckBox()
    2.         .CellBackColor = vbYellow
    3.  
    4. ' In MSFlexGrid1_LeaveCell (under first If condition)
    5.             .CellBackColor = vbWhite
    should do it
    Yes it does...

    I've just noticed what still's not working: when you hit return on the checkbox.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  34. #34
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Checkbox & keydown [as yet unserolved]

    ok, change this sub
    VB Code:
    1. Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    2.     If MSFlexGrid1.Row = CBRow Then
    3.         If KeyAscii = 32 Then
    4.             Check1.Value = Abs(Not CBool(Check1.Value))
    5.         ElseIf KeyAscii = 13 Then
    6.             MSFlexGrid1.Row = MSFlexGrid1.Row + 1
    7.             KeyAscii = 0
    8.         End If
    9.     End If
    10. End Sub
    plus you'll want to add in this one, which i forgot:
    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     If KeyAscii = 13 Then KeyAscii = 0
    3. End Sub

  35. #35

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [as yet unserolved]

    Quote Originally Posted by bushmobile
    ok, change this sub
    VB Code:
    1. Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    2.     If MSFlexGrid1.Row = CBRow Then
    3.         If KeyAscii = 32 Then
    4.             Check1.Value = Abs(Not CBool(Check1.Value))
    5.         ElseIf KeyAscii = 13 Then
    6.             MSFlexGrid1.Row = MSFlexGrid1.Row + 1
    7.             KeyAscii = 0
    8.         End If
    9.     End If
    10. End Sub
    plus you'll want to add in this one, which i forgot:
    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     If KeyAscii = 13 Then KeyAscii = 0
    3. End Sub
    Very good job, bushmobile, that is it! This evening's beer is on me... can you digitize that???
    Attached Images Attached Images  
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  36. #36

  37. #37

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Checkbox & keydown [took some time but... RESOLVED!]

    Here's my current (final?) version. I've made a few minor changes (value of row 4) and fixed scrolling problems. I have set the grid width as:
    VB Code:
    1. tx = Screen.TwipsPerPixelX
    2. With Grid
    3.     'Sum of the widths of all the columns (all have the same
    4.     ' width) plus the widths of the left and 'right borders
    5.     '(times 2, found by trial and error)
    6.     .Width = .ColWidth(0) * nVisibleCols + 4 * .BorderStyle * tx
    7.     'And I have added 3 extra pixels (see below)
    8.     .Width = .Width + 3 * tx
    9. End With
    Depending on the total grid width (play around with the number of extra pixels) some problems appear with scrolling. It appears that you need 2 extra pixels so that the rightmost visible column is considered totally visible, but then another pixel may be necessary to prevent unwanted scrolling effects (try and see).
    All in all I have the feeling that I'm on shaky ground and that the whole thing is a mess.
    Attached Files Attached Files
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width