Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

Detecting Tab key in MS FlexGrid editing

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
mfarid1
Asked:
mfarid1
  • 11
  • 5
1 Solution
 
vim_asteyaCommented:
Q241355- check out this article in MSDN
0
 
vim_asteyaCommented:
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
 
vim_asteyaCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
vim_asteyaCommented:


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
 
vim_asteyaCommented:
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
 
vim_asteyaCommented:
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
 
mfarid1Author Commented:
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
 
vim_asteyaCommented:
Check this one,use a textbox instead of the combo
Q201197 HOWTO: Use a ComboBox to Enter Data into a FlexGrid Control
0
 
vim_asteyaCommented:
U can do as mentioned in MSDN with one textbox also.I have done so
0
 
vim_asteyaCommented:
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
 
mfarid1Author Commented:
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
 
vim_asteyaCommented:
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
 
mfarid1Author Commented:
My email address is

mfarid1@yahoo.com

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

Thanks.

Musleh
0
 
mfarid1Author Commented:
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
 
mfarid1Author Commented:
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
 
vim_asteyaCommented:
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 11
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now