Link to home
Start Free TrialLog in
Avatar of john M
john MFlag for United States of America

asked on

combobox valuemember problem

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

Open in new window

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
    '/////////////////////////////////////////

Open in new window

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

Open in new window


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"
Avatar of Alfredo Luis Torres Serrano
Alfredo Luis Torres Serrano
Flag of United States of America image

The GetFinanceHoldType mehotd is in the same class??
Avatar of john M

ASKER

yes
Avatar of john M

ASKER

attach  is a word doc with what my debug  is
who is Me.fHold in GetFinanceHoldType ?? also there is no attachment in this quesiton
change

            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

With

            With Me.fHold
                .DataSource = FHoldComboItems
                .ValueMember = "getFHold"
                .DisplayMember = "getFHold"
            End With
        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
Avatar of john M

ASKER

Thanks for you help !!!
me.fhold is the sturcture i built  

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

Open in new window



we loopthough the datereader and bind it to the combbox
.Add(New FHoldComboBoxItems(FinanceHoldReader.Item("HoldReason"), IIf(FinanceHoldReader.Item("HoldTest") = True, "1", "0")))

I attached the word doc
the second screen print is what i was talking about above
all you have to do is move the

.DisplayMember = "getFHold"

inside the With Me.fHold

Like this

            With Me.fHold
                .DataSource = FHoldComboItems
                .ValueMember = "getFHold"
                .DisplayMember = "getFHold"
            End With
Avatar of john M

ASKER

thats not what i am really asking

when i do this line of code
  >>>>> Select Case Me.fHold.Text

it returned the 'bouncedcheck  value back
what i need is the value with fholdtest or getfholdtest
you can only assign one  valuemember to each combobox

as i had said with the statment i can see when i run debug

i do a fhold.items(selectindex)  i have this data showing

----fholdcombobocitems
--fhold  "bounced check"
--fholdtest "1"
--getfhold "bounced check"
-- getfholdtest "1"
to get this to work we do a end run on the valuemember to temporary assign it to
what we need then put it back - not good coding

i see the data i need - which is the value of fholdltext ("1")
and how can i get to it without doing the endrun on valuemember

again thanks for this help
I really dont understand what you need but try this

instead do

            With Me.fHold
                .DataSource = FHoldComboItems
                .ValueMember = "getFHold"
                .DisplayMember = "getFHold"
            End With

Just do

           Me.fHold.DataSource = FHoldComboItems
           Me.fHold .ValueMember = "getFHold"
           Me.fHold.DisplayMember = "getFHold"
in those lines you should have the combox populated with the array data.

then

Me.fHold(0).SelectedValue or Me.fHold(1).text should give you what you need.
or if you need to do is a Select Case

in the selectedindex change event

Then

    Private Sub fhold_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles fhold.SelectedIndexChanged
       msgbox fhold.items(fhold.SelectedIndex).tostring
    End Sub


Me.fHold.Text
Avatar of john M

ASKER

see again
the command -            fhold.Items(fHold.SelectedIndex)      
bring be back to this
in bebug i have this
----fholdcombobocitems
--fhold  "bounced check"
--fholdtest "1"
--getfhold "bounced check"
-- getfholdtest "1"
how can i get the fholdtest or getfholdtext

i just need to know how to get it out of there without reassigning the valuemember
What you are saying ia that you have duplicated values in the combox???

 fhold.Items(0)  And  fhold.Items(1) has the same data???
Avatar of john M

ASKER

no
 fhold.items(0) is blank

level 1 has this
----fholdcombobocitems
--fhold  "bounced check"
--fholdtest "1"
--getfhold "bounced check"
-- getfholdtest "1"


level 2 has this
----fholdcombobocitems
--fhold  "NSF"
--fholdtest "0"
--getfhold "nsf"
-- getfholdtest "0"

so when the user selects level 1 or 2
i know the selectindex is set to that level
the old way
when i did >>>>  Select Case Me.fHold.Text
it reutrning 'bounced check'

we want to get back the number assigned in fholdtest    which is 0 or 1
i
 have shown you what the level is hsowing in debug

all i need is how to get the fholdtest or getfhodltest without reassing the valuemember

all i really need is now to get the fholdtest value out of the table i am showing you when i am in debug
ASKER CERTIFIED SOLUTION
Avatar of Alfredo Luis Torres Serrano
Alfredo Luis Torres Serrano
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of john M

ASKER

thanks for your help