Working on the Tab behaviour for my forms I discovered the PreviewKeyDown event. I have to admit it: in about 15 years of VB programming no one gave us such a powerful event. This increases the fire power to the infinite
So I drop down some lines of code I wish to share.
In a new form insert (in the order): a textbox, a reportcontrol, a button (reportcontrol is in the middle) and add this code:
Option Explicit Private Sub Form_Load() Dim i As Integer Dim Record As ReportRecord Dim Item As ReportRecordItem With Me.ReportControl1 For i = 0 To 2 With .Columns.Add(i, "Column" & i, 100, False) .Editable = True End With Next
For i = 1 To 5 Set Record = .Records.Add Set Item = Record.AddItem("") Item.CreateEditOptions Item.EditOptions.AddComboButton True Item.EditOptions.MaxLength = 10 Record.AddItem "" Record.AddItem "" Next i .Populate .AllowEdit = True .FocusSubItems = True .SelectionEnable = True .EditOnClick = True End With End Sub Private Sub ReportControl1_GotFocus() ReportControl1.FocusSubItems = True End Sub Private Sub ReportControl1_PreviewKeyDown(KeyCode As Integer, ByVal Shift As Integer, Cancel As Boolean) Dim intfc As Integer, intfr As Integer ' focused col / row Dim rpt As ReportControl If KeyCode = Asc(vbTab) Then Set rpt = ReportControl1 intfc = -1: intfr = -1 ' On Error Resume Next intfc = rpt.FocusedColumn.Index intfr = rpt.FocusedRow.Index On Error GoTo 0 ' If intfc > -1 Or intfr > -1 Then If Shift > 0 Then If intfc <= 0 Then If intfr = 0 Then rpt.FocusSubItems = False End If End If Else If intfc = rpt.Columns.Count - 1 Then If intfr = rpt.Rows.Count - 1 Then rpt.FocusSubItems = False End If End If End If End If End If
End Sub
|
There are still two questions to resolve:
1) When Shift+Tab from button to ReportControl, the last Row is selected but to edit some row's cell I need to Tab and start from the first column instead of the last (maybe I have to save the RC activecell and restore when enter).
2) When Shift+Tab from RC to textbox and I am in row 0, col 0 the inplacebutton remains visible.
However its enough for start working with a real project .
------------- Product: Xtreme SuitePro (ActiveX) version 13.4.1 / 16.3.0
Platform: Windows Vista (32bit) - SP 2
Language: Visual Basic 6.0 (SP6)
|