|
-
Feb 9th, 2006, 09:20 AM
#1
Thread Starter
Frenzied Member
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:
Private Sub Grd_KeyPress(KeyAscii As Integer)
CallEdit KeyAscii, txtBox
End Sub
Private Sub CallEdit(txtKey As Integer, txtB As Control)
Select Case txtKey
Case 0 To 32
With txtB
.Text = Grd.Text
.SelStart = Len(.Text)
End With
Case Else
With txtB
.Text = Chr(txtKey)
.SelStart = 1
End With
End Select
With Grd
txtB.Move .Left + .CellLeft, _
.Top + .CellTop, _
.CellWidth - 8
End With
txtB.Visible = True
txtB.SetFocus
End Sub
Private Sub Grd_LeaveCell()
If txtBox.Visible = False Then Exit Sub
SaveTxt txtBox
Grd.Col = Grd.Col + 1
Grd.SetFocus
End Sub
Private Sub Grd_GotFocus()
If txtBox.Visible = False Then Exit Sub
SaveTxt txtBox
Grd.Col = Grd.Col + 1
End Sub
Private Sub SaveTxt(txtB As Control)
Grd.Text = txtB.Text
txtB = ""
txtB.Visible = False
End Sub
Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then 'Return
Grd.SetFocus
ElseIf KeyCode = 27 Then 'Escape
txtBox = ""
txtBox.Visible = False
Grd.SetFocus
End If
End Sub
Private Sub txtBox_LostFocus()
Grd.SetFocus
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
-
Feb 9th, 2006, 09:24 AM
#2
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:
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn, vbKeyTab
'move to next cell.
With MSHFlexGrid1
If .Col + 1 <= .Cols - 1 Then
.Col = .Col + 1
Else
If .Row + 1 <= .Rows - 1 Then
.Row = .Row + 1
.Col = 0
Else
.Row = 1
.Col = 0
End If
End If
End With
Case vbKeyBack
With MSHFlexGrid1
'remove the last character, if any.
If Len(.Text) Then
.Text = Left(.Text, Len(.Text) - 1)
End If
End With
Case Is < 32
Case Else
With MSHFlexGrid1
.Text = .Text & Chr(KeyAscii)
End With
End Select
End Sub
Last edited by jcis; Feb 9th, 2006 at 09:29 AM.
-
Feb 9th, 2006, 11:13 AM
#3
Re: Editing MSHFlexgrid
Set the height of the text box.
VB Code:
With Grd
txtB.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth - 8, .CellHeight - 8
End With
-
Feb 9th, 2006, 11:59 AM
#4
Frenzied Member
Re: Editing MSHFlexgrid
I snagged this off another post and used it in my project... works great
VB Code:
Private Sub MSHFlex_KeyPress(KeyAscii As Integer)
With MSHFlex
Select Case KeyAscii
Case 8: 'IF KEY IS BACKSPACE THEN
If .Text <> "" Then .Text = _
Left$(.Text, (Len(.Text) - 1))
Case 13: 'IF KEY IS ENTER THEN
Select Case .Col
Case Is < (.Cols - 1):
SendKeys "{right}"
Case (.Cols - 1):
If (.Row + 1) = .Rows Then
.Rows = .Rows + 1
End If
SendKeys "{home}" + "{down}"
End Select
Case Else
.Text = .Text + Chr$(KeyAscii)
'write your own keyascii Validations under
'commented lines
Select Case .Col
Case 0, 1, 2:
'if (your condition(s)) then
'accept only charectors
'Else
' keyascii=0
'End If
Case Else:
End Select
End Select
End With
End Sub
-
Feb 9th, 2006, 12:56 PM
#5
Re: Editing MSHFlexgrid
 Originally Posted by Besoup
I snagged this off another post and used it in my project... works great
VB Code:
Private Sub MSHFlex_KeyPress(KeyAscii As Integer)
With MSHFlex
Select Case KeyAscii
Case 8: 'IF KEY IS BACKSPACE THEN
If .Text <> "" Then .Text = _
Left$(.Text, (Len(.Text) - 1))
Case 13: 'IF KEY IS ENTER THEN
Select Case .Col
Case Is < (.Cols - 1):
SendKeys "{right}"
Case (.Cols - 1):
If (.Row + 1) = .Rows Then
.Rows = .Rows + 1
End If
SendKeys "{home}" + "{down}"
End Select
Case Else
.Text = .Text + Chr$(KeyAscii)
'write your own keyascii Validations under
'commented lines
Select Case .Col
Case 0, 1, 2:
'if (your condition(s)) then
'accept only charectors
'Else
' keyascii=0
'End If
Case Else:
End Select
End Select
End With
End Sub
This is what I use.
-
Feb 10th, 2006, 05:09 AM
#6
Thread Starter
Frenzied Member
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.
-
Feb 10th, 2006, 05:25 AM
#7
Re: Editing MSHFlexgrid
I tried this and my combo aligns perfectly..
VB Code:
With MSFlexGrid1
.Row = 1
.Col = 1
Combo1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth + 20
.RowHeight(1) = Combo1.Height
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?
-
Feb 10th, 2006, 05:35 AM
#8
Thread Starter
Frenzied Member
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.
-
Feb 10th, 2006, 05:46 AM
#9
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|