Solved

Detecting Tab key in MS FlexGrid editing

Posted on 2001-06-25
16
427 Views
Last Modified: 2012-06-27
I have a MSFlexGrid and textbox which I move over the cells of the grid to make the grid editable. The grid has 4 rows and 3 columns. I would like to make the grid so that I can use Tab key to move through the cells of the grid. That is go from cell 1 to 2 to 3 on row 1. When I click on Tab on the rightmost cell of row 1, I should go to 1st cell of row 2 and so on.

Would appreciate it if actual working code is posted.
Extremely urgent. Any body who answers by 10AM Eastern US time gets an extra 25 points.

Musleh
0
Comment
Question by:mfarid1
  • 11
  • 5
16 Comments
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6226448
Q241355- check out this article in MSDN
0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6226449
it contains the following code

Option Explicit

Private UsingMouse As Boolean  ' Flag for using the Mouse in the Grid.

Private Sub Form_Load()  ' Set Control Property Values
   Text1.TabIndex = 1
   Text2.TabIndex = 2
   Text2.BorderStyle = 0
   Text3.TabIndex = 3
   MSFlexGrid1.Cols = 5
   MSFlexGrid1.Rows = 5
   MSFlexGrid1.TabStop = False
End Sub

Private Sub Text1_LostFocus()
   MSFlexGrid1.Col = 1
   MSFlexGrid1.Row = 1
End Sub

Private Sub Text2_GotFocus()
   MSFlexGrid1.Text = Text2.Text
   If MSFlexGrid1.Col >= MSFlexGrid1.Cols Then MSFlexGrid1.Col = 1
   ChangeCellText
End Sub

0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6226451
Private Sub MSFlexGrid1_EnterCell()  ' Assign cell value to the textbox
   Text2.Text = MSFlexGrid1.Text
End Sub

Private Sub MSFlexGrid1_LeaveCell()
' Assign textbox value to grid

   MSFlexGrid1.Text = Text2.Text
   Text2.Text = ""
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, _
                                  x As Single, y As Single)
   UsingMouse = True
   MSFlexGrid1.Text = Text2.Text
   ChangeCellText
End Sub


0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Expert Comment

by:vim_asteya
ID: 6226453


and.........

Private Sub Text2_LostFocus()
   If UsingMouse = True Then
      UsingMouse = False
      Exit Sub
   End If
   
   If MSFlexGrid1.Col <= MSFlexGrid1.Cols - 2 Then
      MSFlexGrid1.Col = MSFlexGrid1.Col + 1
      ChangeCellText
   Else
      If MSFlexGrid1.Row + 1 < MSFlexGrid1.Rows Then
        MSFlexGrid1.Row = MSFlexGrid1.Row + 1
        MSFlexGrid1.Col = 1
        ChangeCellText
      End If
   End If
End Sub

Public Sub ChangeCellText() ' Move Textbox to active cell.
   Text2.Move MSFlexGrid1.Left + MSFlexGrid1.CellLeft, _
   MSFlexGrid1.Top + MSFlexGrid1.CellTop, _
   MSFlexGrid1.CellWidth, MSFlexGrid1.CellHeight
   Text2.SetFocus
   Text2.ZOrder 0
End Sub

0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6226458
these r other 2 useful links in MSDN

Q201197 HOWTO: Use a ComboBox to Enter Data into a FlexGrid Control
Q187834 HOWTO: Select and Unselect a Range of Cells in MSFlexGrid
0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6226473
these r other 2 useful links in MSDN

Q201197 HOWTO: Use a ComboBox to Enter Data into a FlexGrid Control
Q187834 HOWTO: Select and Unselect a Range of Cells in MSFlexGrid
0
 

Author Comment

by:mfarid1
ID: 6228676
vim_asteya, thank you for answering. The solution Microsoft suggested in Q241355 works with 3 textboxes and not one. Can you give me a solution with 1 textbox?

Musleh
0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6230010
Check this one,use a textbox instead of the combo
Q201197 HOWTO: Use a ComboBox to Enter Data into a FlexGrid Control
0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6230012
U can do as mentioned in MSDN with one textbox also.I have done so
0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6230017
Option Explicit

Private UsingMouse As Boolean  ' Flag for using the Mouse in the Grid.

Private Sub Form_Load()  ' Set Control Property Values
  Text2.TabIndex = 2
  Text2.BorderStyle = 0
    MSFlexGrid1.Cols = 5
  MSFlexGrid1.Rows = 5
  MSFlexGrid1.TabStop = False
End Sub


Private Sub Text2_GotFocus()
  MSFlexGrid1.Text = Text2.Text
  If MSFlexGrid1.Col >= MSFlexGrid1.Cols Then MSFlexGrid1.Col = 1
  ChangeCellText
End Sub

Private Sub MSFlexGrid1_EnterCell()  ' Assign cell value to the textbox
  Text2.Text = MSFlexGrid1.Text
End Sub

Private Sub MSFlexGrid1_LeaveCell()
' Assign textbox value to grid

  MSFlexGrid1.Text = Text2.Text
  Text2.Text = ""
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, _
                                 x As Single, y As Single)
  UsingMouse = True
  MSFlexGrid1.Text = Text2.Text
  ChangeCellText
End Sub

Private Sub Text2_LostFocus()
  If UsingMouse = True Then
     UsingMouse = False
     Exit Sub
  End If
 
  If MSFlexGrid1.Col <= MSFlexGrid1.Cols - 2 Then
     MSFlexGrid1.Col = MSFlexGrid1.Col + 1
     ChangeCellText
  Else
     If MSFlexGrid1.Row + 1 < MSFlexGrid1.Rows Then
       MSFlexGrid1.Row = MSFlexGrid1.Row + 1
       MSFlexGrid1.Col = 1
       ChangeCellText
     End If
  End If
End Sub

Public Sub ChangeCellText() ' Move Textbox to active cell.
  Text2.Move MSFlexGrid1.Left + MSFlexGrid1.CellLeft, _
  MSFlexGrid1.Top + MSFlexGrid1.CellTop, _
  MSFlexGrid1.CellWidth, MSFlexGrid1.CellHeight
  Text2.SetFocus
  Text2.ZOrder 0
End Sub






0
 

Author Comment

by:mfarid1
ID: 6236033
vim_asteya. Thank you again for pasting your code but it doesn't work. I copied you code but Tab doesn't work with it. My main purpose is getting a solution where I can Tab through the cells of the grid.

I tried Q201197. Replaced the combo box with textbox but no luck. Tab doesn't work.

Musleh
0
 
LVL 1

Accepted Solution

by:
vim_asteya earned 300 total points
ID: 6236836
i have a project with a similar code that i paseted here.If u want to have a look at it,give me ur id.
It is a project I developed.to check the working od tab in grid.
0
 

Author Comment

by:mfarid1
ID: 6241467
My email address is

mfarid1@yahoo.com

I guess that's what you mean by id right.

Thanks.

Musleh
0
 

Author Comment

by:mfarid1
ID: 6283652
vim_asteya. Thanks for all the solutions. Unfortunately, your solution did not work. I got you emailed code and tried to work with it. I had to call Microsoft tech support and GetKeyState API call did the trick. I am giving you the points anyway for your efforts.
0
 

Author Comment

by:mfarid1
ID: 6287308
vim_asteya. Thanks for all the solutions. Unfortunately, your solution did not work. I got you emailed
code and tried to work with it. I had to call Microsoft tech support and GetKeyState API call did the
trick. I am giving you the points anyway for your efforts.
0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6288396
When i havent given u the solution,i dont think its fair to accept points.I didnt do it for points though.
If there is anyway of undoing the action of giving those points,pls do it,i would appreciate that.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question