Home All Groups Group Topic Archive Search About

Summary of my experience with combo box, any further suggestions ?

Author
11 Jan 2006 5:06 PM
Mark L. Breen
Hello All,

I have been playing with a combo box for the last day or so, attempting to
get my head around the best or the recommended way to update them.

I had problems setting the .Text and also the .SelectedValue and also the
..SelectedText.  Following comments and suggestions on the newsgroups I
settled on using the .SelectedIndex.

Below is a snippit of my code.  What I do not like about it is the loop
through the entire contents of the combo box.   This seems ridiculously
labour intensive.  Is there are more direct way to find the index of a value
in the combo list of items?

Thanks All

Mark in Ireland




Private Function F_intGetIndexForCombo(ByVal cbo As ComboBox, ByVal
intUniqueId As Integer) As Integer
        Dim intIndex As Integer
        For intCount As Integer = 0 To cbo.Items.Count
            cbo.SelectedIndex = intCount
            If cbo.SelectedValue = mobjRecord.PIDTypeId Then
                intIndex = intCount
                Exit For
            End If
        Next
        F_intGetIndexForCombo = intIndex
End Function



    Private Sub S_PopulateControls()

        Me.txtSessionId.Text = mobjRecord.SessionId
        Me.cboPIDType.SelectedIndex = F_intGetIndexForCombo(Me.cboPIDType,
mobjRecord.PIDTypeId)
        Me.cboLocalisedText.SelectedIndex =
F_intGetIndexForCombo(Me.cboLocalisedText, mobjRecord.LocalisedTestId)
        Me.txtPartNum.Text = mobjRecord.PartNum
        Me.txtDescription.Text = mobjRecord.Description
        Me.txtCreated.Text = mobjRecord.Created
        Me.txtComments.Text = mobjRecord.Comment
        Me.chkActiveYN.CheckState =
CommonRoutines.F_CnvBooleanToCheckState(mobjRecord.Active)

    End Sub

Author
11 Jan 2006 5:56 PM
Chris Dunaway
Have you tried the ComboBox.Items.IndexOf  method?  And you might also
checkout the DisplayValue property as well.
Author
12 Jan 2006 1:59 AM
Dennis
Not sure what mobjRecord.PIDTypeId  is but if it's a string that in the
combobox, try

mycombobox.SelectedIndex=mycombobox.FindStringExact(mobjRecord.PIDTypeId )
--
Dennis in Houston


Show quoteHide quote
"Mark L. Breen" wrote:

> Hello All,
>
> I have been playing with a combo box for the last day or so, attempting to
> get my head around the best or the recommended way to update them.
>
> I had problems setting the .Text and also the .SelectedValue and also the
> ..SelectedText.  Following comments and suggestions on the newsgroups I
> settled on using the .SelectedIndex.
>
> Below is a snippit of my code.  What I do not like about it is the loop
> through the entire contents of the combo box.   This seems ridiculously
> labour intensive.  Is there are more direct way to find the index of a value
> in the combo list of items?
>
> Thanks All
>
> Mark in Ireland
>
>
>
>
> Private Function F_intGetIndexForCombo(ByVal cbo As ComboBox, ByVal
> intUniqueId As Integer) As Integer
>         Dim intIndex As Integer
>         For intCount As Integer = 0 To cbo.Items.Count
>             cbo.SelectedIndex = intCount
>             If cbo.SelectedValue = mobjRecord.PIDTypeId Then
>                 intIndex = intCount
>                 Exit For
>             End If
>         Next
>         F_intGetIndexForCombo = intIndex
> End Function
>
>
>
>     Private Sub S_PopulateControls()
>
>         Me.txtSessionId.Text = mobjRecord.SessionId
>         Me.cboPIDType.SelectedIndex = F_intGetIndexForCombo(Me.cboPIDType,
> mobjRecord.PIDTypeId)
>         Me.cboLocalisedText.SelectedIndex =
> F_intGetIndexForCombo(Me.cboLocalisedText, mobjRecord.LocalisedTestId)
>         Me.txtPartNum.Text = mobjRecord.PartNum
>         Me.txtDescription.Text = mobjRecord.Description
>         Me.txtCreated.Text = mobjRecord.Created
>         Me.txtComments.Text = mobjRecord.Comment
>         Me.chkActiveYN.CheckState =
> CommonRoutines.F_CnvBooleanToCheckState(mobjRecord.Active)
>
>     End Sub
>
>
>