Re: combobox find item by value
- From: "RobinS" <RobinS@xxxxxxxxxxxxxxx>
- Date: Thu, 16 Nov 2006 16:40:30 -0800
Set the text property equal to what you want it to be. If it's in the
display list, it will select that entry.
I added this to Form_Load for one of mine. When SelectedIndex
changes, my combo box loads a separate part of the screen.
I did this:
myComboBox.SelectedValue = 0 'this makes it have none selected
myComboBox.Text = "TextOfThirdEntry"
Then when I look at myComboBox.SelectedValue, it's the index
for the one I put the text in for, and the separate part of the
screen has loaded for the right entry.
Note: If you don't set SelectedValue to 0 before doing this,
it equals Nothing, and could impact your results, depending
on what you're doing.
Is that what you're trying to accomplish?
Robin S.
----------------------------
"Jason" <Jason@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9E14EF6B-5C5A-41C3-877C-052D872BEDEA@xxxxxxxxxxxxxxxx
Ok, I see, sorry for the confussion, I'm talking about a Windows app, the
combobox has a ValueMember property and a DisplayMember property, so once
I
populate the combo box with say all the states, when the user loads a
particular record in which the state is NY, I need to set the selecteditem
to
NY, but in the database I'm only going to store the ID for NY, and if I do
a
.IndexOf(state), it will not match up because the state object in the
combobox will have name, id, etc., and the object I'm passing it only has
the
ID, which will cause the comparison the fail, anyway I can use the id to
set
the selected item or get the index?
Jason
"Ciaran O''Donnell" wrote:
I'm not sure if your talking web or windows as in windows apps, the list
items in a combobox are objects (so they dont necesarily have a value
property), so if the object you put it there overrides equals, you can
just
do comboBox1.Items.IndexOf(value)
On the web there is a FindItemByValue on the items collection. This
returns
the actual item so if you wanted the index you could then do an index of.
HTH
Ciaran O'Donnell
"Jason" wrote:
Is there any way in a combobox to find the index of an item or set the
item
in a combobox by the value? I know there is a FindString, and a
FindStringExact method in the combobox object, but is there anything
simmilar
or any work around to getting the index of an object or setting the
selecteditem by the value? Any help is appreciated, thank you.
.
- Follow-Ups:
- Re: combobox find item by value
- From: Jason
- Re: combobox find item by value
- From: Kevin Yu [MSFT]
- Re: combobox find item by value
- Prev by Date: Re: IO.Compression and Encryption
- Next by Date: Re: How do I Sleep for a specified amount of time and relinquish c
- Previous by thread: Re: How do I Sleep for a specified amount of time and relinquish c
- Next by thread: Re: combobox find item by value
- Index(es):
Relevant Pages
|