开发者

How Can I Assign TabIndex in runtime in VB6

开发者 https://www.devze.com 2023-02-17 09:09 出处:网络
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.

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 ?


Suppose you have 5 controls on a form and their tab order is like this

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

If you change 3 to 1 Then it will look like this

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

Visual Basic will automatically bump up by one all tabindex equal to and higher than the one you assigned. There will never be a time where two controls have the same tabindex. This causes problems for routines that assign tab indexes like yours.

What you should do is not assign the tabindex directly from the database but rather build an array of control indexes associated with tab indexes. Sort it based on the tabindex and then start assigning, starting at whatever is at tabindex 0 (or the lowest).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号