Results 1 to 9 of 9

Thread: RESOLVED -> Editing MSHFlexgrid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    RESOLVED -> Editing MSHFlexgrid

    Hi all,

    I'm developing an application that has an editable MSHFlexgrid - using a textbox to make the editions. The form has an MSHFlexgrid (grd) and an invisible textbox (txtbox). The code, in it's simplist form is as follows.
    VB Code:
    1. Private Sub Grd_KeyPress(KeyAscii As Integer)
    2.    
    3.     CallEdit KeyAscii, txtBox
    4.    
    5. End Sub
    6.  
    7. Private Sub CallEdit(txtKey As Integer, txtB As Control)
    8.  
    9.     Select Case txtKey
    10.         Case 0 To 32
    11.             With txtB
    12.                 .Text = Grd.Text
    13.                 .SelStart = Len(.Text)
    14.             End With
    15.         Case Else
    16.             With txtB
    17.                 .Text = Chr(txtKey)
    18.                 .SelStart = 1
    19.             End With
    20.     End Select
    21.  
    22.     With Grd
    23.         txtB.Move .Left + .CellLeft, _
    24.             .Top + .CellTop, _
    25.             .CellWidth - 8
    26.     End With
    27.  
    28.     txtB.Visible = True
    29.     txtB.SetFocus
    30.  
    31. End Sub
    32.  
    33. Private Sub Grd_LeaveCell()
    34.  
    35.     If txtBox.Visible = False Then Exit Sub
    36.  
    37.     SaveTxt txtBox
    38.  
    39.     Grd.Col = Grd.Col + 1
    40.     Grd.SetFocus
    41.  
    42. End Sub
    43.  
    44. Private Sub Grd_GotFocus()
    45.    
    46.     If txtBox.Visible = False Then Exit Sub
    47.  
    48.     SaveTxt txtBox
    49.     Grd.Col = Grd.Col + 1
    50.    
    51. End Sub
    52.  
    53. Private Sub SaveTxt(txtB As Control)
    54.  
    55.     Grd.Text = txtB.Text
    56.     txtB = ""
    57.     txtB.Visible = False
    58.  
    59. End Sub
    60.  
    61. Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)
    62.  
    63.     If KeyCode = 13 Then        'Return
    64.         Grd.SetFocus
    65.     ElseIf KeyCode = 27 Then    'Escape
    66.         txtBox = ""
    67.         txtBox.Visible = False
    68.         Grd.SetFocus
    69.     End If
    70.  
    71. End Sub
    72.  
    73. Private Sub txtBox_LostFocus()
    74.  
    75.     Grd.SetFocus
    76.  
    77. End Sub
    So when the user starts typing in a cell the text box appears in that cell (seamlessly), when the user tabs or returns on the textbox, the text is entered into the grid. To the user it should looks like they are typing directly in the grid. I've done this loads of times before for other applications without a hassle. But the problem I'm having now on one PC is when typing in the grid, the textbox doesn't line up with the cell to be edited. It seems to be over more to the right and below the cell. I've been testing this application on a few PCs and there's no problem with any of the others, only this one. Can anyone help?
    Last edited by mel_flynn; Feb 13th, 2006 at 04:52 AM.
    Mel

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Editing MSHFlexgrid

    Why don't you use this method? It's more flexible and you don't need a textbox. You can change its behavior by adding different code for each key in Select Case.
    VB Code:
    1. Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
    2.    Select Case KeyAscii
    3.         Case vbKeyReturn, vbKeyTab
    4.         'move to next cell.
    5.             With MSHFlexGrid1
    6.                 If .Col + 1 <= .Cols - 1 Then
    7.                     .Col = .Col + 1
    8.                 Else
    9.                     If .Row + 1 <= .Rows - 1 Then
    10.                         .Row = .Row + 1
    11.                         .Col = 0
    12.                     Else
    13.                         .Row = 1
    14.                         .Col = 0
    15.                     End If
    16.                 End If
    17.             End With
    18.         Case vbKeyBack
    19.             With MSHFlexGrid1
    20.                 'remove the last character, if any.
    21.                 If Len(.Text) Then
    22.                     .Text = Left(.Text, Len(.Text) - 1)
    23.                 End If
    24.             End With
    25.            
    26.         Case Is < 32
    27.        
    28.         Case Else
    29.             With MSHFlexGrid1
    30.                 .Text = .Text & Chr(KeyAscii)
    31.             End With
    32.     End Select
    33. End Sub
    Last edited by jcis; Feb 9th, 2006 at 09:29 AM.

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Editing MSHFlexgrid

    Set the height of the text box.

    VB Code:
    1. With Grd
    2.    txtB.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth - 8, .CellHeight - 8
    3. End With

  4. #4
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Editing MSHFlexgrid

    I snagged this off another post and used it in my project... works great

    VB Code:
    1. Private Sub MSHFlex_KeyPress(KeyAscii As Integer)
    2.    With MSHFlex
    3.         Select Case KeyAscii
    4.                
    5.             Case 8: 'IF KEY IS BACKSPACE THEN
    6.                 If .Text <> "" Then .Text = _
    7.                  Left$(.Text, (Len(.Text) - 1))
    8.             Case 13: 'IF KEY IS ENTER THEN
    9.                 Select Case .Col
    10.                     Case Is < (.Cols - 1):
    11.                         SendKeys "{right}"
    12.                     Case (.Cols - 1):
    13.                         If (.Row + 1) = .Rows Then
    14.                             .Rows = .Rows + 1
    15.                         End If
    16.                         SendKeys "{home}" + "{down}"
    17.                 End Select
    18.             Case Else
    19.                 .Text = .Text + Chr$(KeyAscii)
    20.                 'write your own keyascii Validations under
    21.                        'commented lines
    22.                 Select Case .Col
    23.                     Case 0, 1, 2:
    24.                         'if (your condition(s)) then
    25.                             'accept only charectors
    26.                         'Else
    27.                         '   keyascii=0
    28.                         'End If
    29.                     Case Else:
    30.                 End Select
    31.         End Select
    32.     End With
    33.  
    34. End Sub

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Editing MSHFlexgrid

    Quote Originally Posted by Besoup
    I snagged this off another post and used it in my project... works great

    VB Code:
    1. Private Sub MSHFlex_KeyPress(KeyAscii As Integer)
    2.    With MSHFlex
    3.         Select Case KeyAscii
    4.                
    5.             Case 8: 'IF KEY IS BACKSPACE THEN
    6.                 If .Text <> "" Then .Text = _
    7.                  Left$(.Text, (Len(.Text) - 1))
    8.             Case 13: 'IF KEY IS ENTER THEN
    9.                 Select Case .Col
    10.                     Case Is < (.Cols - 1):
    11.                         SendKeys "{right}"
    12.                     Case (.Cols - 1):
    13.                         If (.Row + 1) = .Rows Then
    14.                             .Rows = .Rows + 1
    15.                         End If
    16.                         SendKeys "{home}" + "{down}"
    17.                 End Select
    18.             Case Else
    19.                 .Text = .Text + Chr$(KeyAscii)
    20.                 'write your own keyascii Validations under
    21.                        'commented lines
    22.                 Select Case .Col
    23.                     Case 0, 1, 2:
    24.                         'if (your condition(s)) then
    25.                             'accept only charectors
    26.                         'Else
    27.                         '   keyascii=0
    28.                         'End If
    29.                     Case Else:
    30.                 End Select
    31.         End Select
    32.     End With
    33.  
    34. End Sub
    This is what I use.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Re: Editing MSHFlexgrid

    That's great alright, thanks.

    But I have a number of Combo boxes and Multiline text boxes that I am using in conjunction with my grid. So I still have the problem with the alignment. As I said, I have tested this on a number of PCs & there's no problem, it's just this one PC. Very fustrating.
    Mel

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Editing MSHFlexgrid

    I tried this and my combo aligns perfectly..
    VB Code:
    1. With MSFlexGrid1
    2.         .Row = 1
    3.         .Col = 1
    4.         Combo1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth + 20
    5.         .RowHeight(1) = Combo1.Height
    6.     End With
    But, as you said the problem occurs just in 1 PC. Maybe that one has a different resolution? is it a laptop pc?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Re: Editing MSHFlexgrid

    Yeah I reckon it's something to do with the graphics card or something on that PC. The screen resolution is set to 1024*768 - same as mine. However, the applications appearance is different to mine. I don't know, I reckon I'll just have to compensate the alignment difference myself. It'll be a pain to fingure the exact amount it's out by, but what can I do.

    Thanks anyway.
    Mel

  9. #9
    Addicted Member
    Join Date
    Jan 2006
    Location
    PUNE
    Posts
    222

    Re: Editing MSHFlexgrid

    Nice Thread
    thanks all of u
    am also using MSH Flexgrid i need to be edited
    All u have u Contributed Well

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