|
-
Sep 6th, 2000, 12:09 PM
#1
Thread Starter
PowerPoster
How can I allow a user to type into a msflexgrid? i have tree columns that represent day, week, and month value and would like the user to supply in the grid. Any ideas on this matter would be greatly appereciated.
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 6th, 2000, 12:57 PM
#2
Fanatic Member
Code:
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, MSFlexGrid1.ColSel) = MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, MSFlexGrid1.ColSel) & Chr$(KeyAscii)
End Sub
-
Sep 6th, 2000, 02:08 PM
#3
Thread Starter
PowerPoster
Mad Compie,
You are the man. I thought I would have to revert to a DBGrid. Something so hard, yet so simple. Thanks, you saved me a hell of alot of redoing...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 6th, 2000, 02:16 PM
#4
Thread Starter
PowerPoster
Mad Compie: or anyone who may reply,
New question same subject.
As before, my three input columns will be numeric, but how can i make it so that the user can use the backspace key and delete key for edit purposes. What I've done so far works, except if the user must change the typed in value.
Please help.
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 6th, 2000, 03:25 PM
#5
New Member
I had the same problem as you and I found a solution finally 
You have to use a textbox that you dont make visible in a first time.
You place the textbox at the same Left and Top of your MSFlexGrid.
Code:
TextBox.Visible = False
TextBox.Top = MSFlexGrid.Top
TextBox.Left = MSFlexGrid.Left
When the user click on the cell you want, you have to display the textbox but before place it over the cell :
Code:
TextBox.Left = TextBox.Left + MSFlexGrid.CellLeft
TextBox.Top = TextBox.Top + MSFlexGrid.CellTop
TextBox.Visible = True
TextBox.SetFocus
And you have to play with the KeyPress event of the TextBox.
If "Enter" (13) is pressed by the user, the textbox return to his initial place, is invisible, and the cell contains the text write in the textbox.
Code:
Private Sub TextBox_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn
MSFlexGrid.TextMatrix(MSFlexGrid.Row, MSFlexGrid.Col) = TextBox.Text
TextBox.Visible = False
TextBox.Left = MSFlexGrid.Left
TextBox.Top = MSFlexGrid.Top
Case vbKeyBack
TextBox.Text = Left(TextBox.Text, Len(TextBox.Text) - 1)
End Select
End Sub
You can do a lot a things such as move the textbox to the next cell when the user press the up/down key or left/right key.
Nicolas Joannidès
Visual Basic, C, ASP
[email protected]
-
Sep 7th, 2000, 12:31 PM
#6
Fanatic Member
There is also an API that handles numeric key presses:
Code:
'This project needs a TextBox
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const GWL_STYLE = (-16)
Const ES_NUMBER = &H2000&
Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)
Dim curstyle As Long, newstyle As Long
'retrieve the window style
curstyle = GetWindowLong(NumberText.hwnd, GWL_STYLE)
If Flag Then
curstyle = curstyle Or ES_NUMBER
Else
curstyle = curstyle And (Not ES_NUMBER)
End If
'Set the new style
newstyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, curstyle)
'refresh
NumberText.Refresh
End Sub
Private Sub Form_Load()
SetNumber Text1, True
Me.Caption = "Now, try typing some letters into the textbox"
End Sub
-
Sep 25th, 2000, 01:05 PM
#7
How can we do to limit only numbers in the grids but not in the textbox, can we do that by using api? because i need to move the textbox from grid to grid... and needs lots of code... hope i can use api to control the entry and use what was mentioned (the best codes) above that can save lots of time
dragon
-
Sep 26th, 2000, 12:53 PM
#8
Fanatic Member
I don't think there is any API to do this. You should write your own code to convert (to filter) the TextBox Text property to the grid TextMatrix property.
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
|