Solved

Setting the selected index of a combobox with only a value

Posted on 2006-07-12
6
250 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
Comment Utility
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
Comment Utility
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
Comment Utility
When a databound combobox is set to dropdownlist i find that simply combobox.text="Description" seems to set the correct item.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

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

Author Comment

by:JPERKS1985
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

8 Experts available now in Live!

Get 1:1 Help Now