2

I am working in a VB6 maintenance application. It is a windows based application. My client wants to configure the controls tab index at runtime. I am saving the client setting to the access database.

The following sub sets the tab index of the controls

Private Sub SetTabSetting()
Dim i As Integer
Dim Ctr As Control
If UBound(TSetting) > 0 Then
    For i = 0 To UBound(TSetting)
        For Each Ctr In Me.Controls
            Dim matched As Boolean: matched = False

            If Ctr.Name = TSetting(i).ControlName Then
               Ctr.TabIndex = TSetting(i).TabIndexNum
               Exit For
            End If
        Next
    Next
End If
End Sub

TSetting is a TYPE Array defined in a Global Module.

Private Sub Form_Load()
  GetRATabSetting
  SetRATabSetting
End Sub

GetRATabSetting is extracting the values from the database and populating into the TYPE arrray.

The code is getting executed quite fine. Even the values get extracted from the database and set to the controls correctly. But the tab is following the index what is set in the designtime.

Am I doing any mistake? Is it possible to set the tabindex of the controls at runtime ? Is there any other way to perform this ?

4

1 に答える 1

4

フォームに 5 つのコントロールがあり、それらのタブ オーダーが次のようになっているとします。

Index - TabIndex
1 - 0
2 - 1
3 - 2
4 - 3
5 - 4

3を1に変えるとこうなります

Index - TabIndex
1 - 0
2 - 2
3 - 1
4 - 3
5 - 4

Visual Basic は、割り当てたタブインデックス以上のすべてのタブインデックスを自動的に 1 つ増やします。2 つのコントロールが同じタブインデックスを持つことは決してありません。これは、あなたのようなタブ インデックスを割り当てるルーチンに問題を引き起こします。

データベースから tabindex を直接割り当てるのではなく、タブ インデックスに関連付けられたコントロール インデックスの配列を作成する必要があります。tabindex に基づいて並べ替えてから、tabindex 0 (または最小) にあるものから割り当てを開始します。

于 2011-03-15T12:26:40.917 に答える