GetComboIdx Method

Build 1501 on 14/Nov/2017  This topic last edited on: 22/Mar/2016, at 17:09

Description

Returns the index of the item, selected in a combo box, or in a switch item.

Note: in combo.AddItem("Above", 456), name is "Above", index is 0, and data is 456.

Syntax

retvalue = object.GetComboIdx (po)

object

Required. Object name, returned by Dim idlg As InputDlg = New InputDlg.

po

identifier, assigned to the combo during creation, e.g. Dim po = idlg.AddCombo("Position", combo, combo.ToIdx(789)), or the ordinal number of control in dialog (see example 2 for more information).

Examples

1. In this example, the message box displays the value of the combo entry, the idx of the selected item and the string of that combo entry, when you clicked Ok or pressed Return. The first item is 0, the second item is 1 and so on.

Dim idlg As InputDlg = New InputDlg

idlg.Title = "My title"

 

Dim combo As InputDlg.Combo = New InputDlg.Combo

combo.AddItem("Above", 456)

combo.AddItem("Below", 789)

Dim po = idlg.AddCombo("Position", combo, combo.ToIdx(789))

If idlg.ShowDialog Then                            ' if OK was clicked...

  MsgBox(idlg.GetComboData(po) & vbCr & _

         idlg.GetComboIdx(po) & vbCr & _

         idlg.GetComboStr(po))                 ' return the value of field with index iNum

End If

2. In this example, we have two combo boxes, but we're using the same identifier cb for all of them. Please note the command cb.Items.Clear() that clears items between two definitions. Now, as this dialog box has three controls (combo, integer, combo), to read values we use the ordinal number of control (the first control has ordinal number 0, the second is 1 and so on). Therefore:

      Dim mode = dlg.GetComboIdx(0)

      Dim val = Math.Abs(CShort(dlg.GetItemValue(1)))

      Dim apply = dlg.GetComboIdx(2)

mode returns the index of the first control (first combo), val returns the value of the integer control, and apply the index of the second combo.

Full code:

<ShellCommand(CanExecute:="Ena_HasSelPage")> _

  Public Sub PageRenumberDlg()

    Dim dlg As New InputDlg

    dlg.Width = 350

    dlg.Title = My.Resources.IDS_PRD1 '"Page renumber"

 

    Dim cb As New InputDlg.Combo

    cb.AddItem(My.Resources.IDS_PRD2, 0)

    cb.AddItem(My.Resources.IDS_PRD3, 0)

    cb.AddItem(My.Resources.IDS_PRD4, 0)

 

    dlg.AddCombo(My.Resources.IDS_PRD5, cb, 0)

    dlg.AddInt(My.Resources.IDS_Value, 1)

 

    cb.Items.Clear()

    cb.AddItem(My.Resources.IDS_SelPages, 0)

    cb.AddItem(My.Resources.IDS_AllPages, 0)

    dlg.AddCombo(My.Resources.IDS_ApplyTo, cb, 0)

 

    If dlg.ShowDialog() Then

      Dim mode = dlg.GetComboIdx(0)

      Dim val = Math.Abs(CShort(dlg.GetItemValue(1)))

      Dim apply = dlg.GetComboIdx(2)

 

      Dim delta As Short = val

      Dim start As Short = 0

      If mode = 0 Then

        delta = 0

        start = val

      End If

      Dim allpages As Boolean = apply = 1

      PageRenumberEx(delta, start, allpages)

    End If

  End Sub

See also

GetComboData, GetComboStr

AddCombo