?
Solved

Detecting Tab key in MS FlexGrid editing

Posted on 2001-06-25
16
Medium Priority
?
442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

771 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