troubleshooting Question

combobox valuemember problem

Avatar of john M
john MFlag for United States of America asked on
Visual Basic Classic.NET Programming
16 Comments1 Solution402 ViewsLast Modified:
I load a combo box using this code


Private Sub GetFinanceHoldType()

        ' declare data reader
        Dim FinanceHoldReader As SqlDataReader = Nothing

        Try

            'disable the read only property
            Me.fHold.DropDownStyle = ComboBoxStyle.DropDown

            ' clear the combo datasource
            With Me.fHold
                .DataSource = Nothing
            End With

            ' Get the Finance Hold types through a data reader
            FinanceHoldReader = GetFinanceHold_020912() 'JPM1
            'bind to an arraylist that contains entries based on the the structure that
            ' has been defined FHoldComboItems.
            Dim FHoldComboItems As New ArrayList


            'add a empty string value as the first item
            With FHoldComboItems
                .Add(New FHoldComboBoxItems("", ""))
            End With

            ' add the values from the datareader
            While FinanceHoldReader.Read
                With FHoldComboItems
                    '.Add(New FHoldComboBoxItems(FinanceHoldReader.Item("HoldReason")))
                    .Add(New FHoldComboBoxItems(FinanceHoldReader.Item("HoldReason"), IIf(FinanceHoldReader.Item("HoldTest") = True, "1", "0")))

                End With


            End While

            'close the data reader
            FinanceHoldReader.Close()

            'bind the arraylist to the combo box 
            With Me.fHold
                .DataSource = FHoldComboItems
                .ValueMember = "getFHold"
                ' .ValueMember = "getFHold

            End With

            ' Show the Finance Hold types
            Me.fHold.DisplayMember = "getFHold"

        Catch ex As Exception
            ' in case of an error, return the message
            MsgBox(ex.Message)

        Finally
            ' close the datareader in case it's still open
            If Not (FinanceHoldReader Is Nothing) Then
                FinanceHoldReader.Close()
            End If

        End Try

    End Sub
end code
i build the stucture using this code
Protected Structure FHoldComboBoxItems
        Private FHold As String
        Private FHoldTest As String

        Public Sub New(ByVal Hold As String, ByVal HoldTest As String)
            FHold = Hold
            FHoldTest = HoldTest
        End Sub


        Public ReadOnly Property getFHold() As String
            Get
                Return FHold
            End Get
        End Property
        Public ReadOnly Property getFHoldtest() As String '
            Get
                Return FHoldTest
            End Get
        End Property
    End Structure
    '/////////////////////////////////////////
then the old way i would this to check for the valuemember
using the me.fhold.text i get what was entered back


]
old code to return other field which works
        NSFChanged = "Clean"
           Select Case Me.fHold.Text
            Case "Bounced Check", "Credit Card Charge Back"
                Select Case Me.fHold.ValueMember
                    Case "Bounced Check", "Credit Card Charge Back"
                        '  NSF is already there, don't update
                    Case Else
                        '  there() 's no bounced check or CC charge back yet, update main record
                        NSFChanged = "UpdateNSF"

                End Select
        End Select

so i end up with this when i use debug

doign the command
fhold.items(1)
gives me
How do i get the value for fhold or getfhold

----fholdcombobocitems
--fhold  "bounced check"
--fholdtest "1"
--getfhold "bounced check"
-- getfholdtest "1"
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 16 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros