Solved

Detecting Tab key in MS FlexGrid editing

Posted on 2001-06-25
16
423 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
Comment Utility
Q241355- check out this article in MSDN
0
 
LVL 1

Expert Comment

by:vim_asteya
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:vim_asteya
Comment Utility


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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Check this one,use a textbox instead of the combo
Q201197 HOWTO: Use a ComboBox to Enter Data into a FlexGrid Control
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

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

Expert Comment

by:vim_asteya
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
My email address is

mfarid1@yahoo.com

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

Thanks.

Musleh
0
 

Author Comment

by:mfarid1
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now