Solved

Setting the selected index of a combobox with only a value

Posted on 2006-07-12
6
266 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
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 500 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET return row from SQL to DataSet and get column values ? 3 102
Help with error in Query 2 31
vb.net Configuration, settings file location? 8 31
Groupbox Control ? 2 19
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…

828 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