Solved

Setting the selected index of a combobox with only a value

Posted on 2006-07-12
6
261 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now