?
Solved

Setting the selected index of a combobox with only a value

Posted on 2006-07-12
6
Medium Priority
?
269 Views
Last Modified: 2012-05-05
I need to be able to set the selectedindex of a combobox by only knowing the value that it needs to be selected to.

cb.DropDownStyle = ComboBoxStyle.DropDownList

    If Not dtForm.Rows(R).Item("UserSelection") = "NULL" Then
       cb.SelectedValue = dtForm.Rows(R).Item("UserSelection")
 End If


 dtForm.Rows(R).Item("UserSelection") will give me say the string "TESTING123", "TESTING123" has already been added to that combox but it needs to be selected because  dtForm.Rows(R).Item("UserSelection") returned "TESTING123".


0
Comment
Question by:JPERKS1985
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17097497
Dim index as Integer
index = cb.FindStringExact(dtForm.Rows(R).Item("UserSelection"))

if index >= 0 then
  cb.SelectedIndex = index
end if
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 2000 total points
ID: 17097512
I think just
    cb.SelectedItem = "TESTING123"
would also work, if the items added to the Combo are just text

0
 
LVL 9

Expert Comment

by:lojk
ID: 17098960
When a databound combobox is set to dropdownlist i find that simply combobox.text="Description" seems to set the correct item.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:JPERKS1985
ID: 17105273
none of these suggestions have worked. what a weird problem.
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 17105281
There was code below that code that would reset the values

  If Not dtForm.Rows(R).Item("UserSelection") = "NULL" Then
                  cb.SelectedItem = dtForm.Rows(R).Item("UserSelection")
            End If


Ended up working once I moved the code below the ocnflicting code. Thanks everyone.
0
 
LVL 1

Expert Comment

by:Emanuele_Ciriachi
ID: 20341689
Oh, and I found out why: I was using reflection, so that when I call

frm.Visible = True

its LoadData method is fired; this method will mess up with the global OleDbDataReader which is my DR, making a mess. Now I fixed everything using a different, custom DataReader in this function, and not the global one. Sorry for wasting your time, thanks anyway.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question