Re: combobox find item by value

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.


.



Relevant Pages

  • Re: Arraylist question
    ... new info in, such as age is changing, I want to update with the latest age? ... > Now you can add the instances of person directly to the combobox which will ... > back out of the Combobox by using the SelectedItem property i.e. ... >> public int CompareTo ...
    (microsoft.public.dotnet.languages.csharp)
  • VB 2005 Newbie - Binding?
    ... On my combobox for location I have in my databindings property for example: ... SelectedItem: M_BTADSLBindingSource - LocationsID ... However when I run my project I only get the first Location showing in the ... Location in the ComboBox to reflect the one for that row in th database, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: combobox find item by value
    ... No that is not what I'm trying to do, I'm starting off with a combobox ... particular record in which the state is NY, I need to set the selecteditem ... "Ciaran O''Donnell" wrote: ... property), so if the object you put it there overrides equals, you can ...
    (microsoft.public.dotnet.framework)
  • Re: Autovervollständigen von Comboboxen - was mache ich falsch
    ... > Public Function GetCorrectSelectedItem() As Object ... > Dann spielt es keine Rolle, was die ComboBox glaubt, selektieren zu ... SelectedItem ist tatsächlich ein Thema. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Frage zu SelectedItem
    ... die SelectedItem Methode benutzt die IndexOf Methode der Item Collection. ... Die IndexOf Methode benutzt equals un auf Gleichheit zu testen. ... Letzlich wird übrigens innerhalb der SelectedItem Methode die SelectedIndex ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)