john M
asked on
combobox valuemember problem
I load a combo box using this code
using the me.fhold.text i get what was entered back
]
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"
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 codeProtected 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 valuememberusing 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"
The GetFinanceHoldType mehotd is in the same class??
ASKER
yes
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
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
ASKER
Thanks for you help !!!
me.fhold is the sturcture i built
see above code
we loopthough the datereader and bind it to the combbox
.Add(New FHoldComboBoxItems(Finance HoldReader .Item("Hol dReason"), IIf(FinanceHoldReader.Item ("HoldTest ") = True, "1", "0")))
I attached the word doc
the second screen print is what i was talking about above
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'
we loopthough the datereader and bind it to the combbox
.Add(New FHoldComboBoxItems(Finance
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
.DisplayMember = "getFHold"
inside the With Me.fHold
Like this
With Me.fHold
.DataSource = FHoldComboItems
.ValueMember = "getFHold"
.DisplayMember = "getFHold"
End With
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
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"
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.
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.Selected Index).tos tring
End Sub
Me.fHold.Text
in the selectedindex change event
Then
Private Sub fhold_SelectedIndexChanged
msgbox fhold.items(fhold.Selected
End Sub
Me.fHold.Text
ASKER
see again
the command - fhold.Items(fHold.Selected Index)
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
the command - fhold.Items(fHold.Selected
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???
fhold.Items(0) And fhold.Items(1) has the same data???
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for your help