Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4096442
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:02:49+00:00 2026-05-20T20:02:49+00:00

Question: My combobox (Me.cbHomeDrive) doesn’t get properly initialized if I use Me.cbHomeDrive.SelectedText = E:

  • 0

Question:

My combobox (Me.cbHomeDrive) doesn’t get properly initialized if I use

Me.cbHomeDrive.SelectedText = "E:"

On Form_Load:

For i As Integer = AscW("C"c) To AscW("Z"c) Step 1
      Me.cbHomeDrive.Items.Add(New ComboBoxItem(ChrW(i) + ":"))
Next

Me.cbHomeDrive.SelectedIndex = 26 - 3
Me.cbHomeDrive.Enabled = False

With class ComboBoxItem being:

Public Class ComboBoxItem
    Public Text As String
    Public ID As String

    Public Sub New(ByVal strText As String)
        Text = strText
        ID = strText
    End Sub

    Public Sub New(ByVal strText As String, ByVal strID As String)
        Text = strText
        ID = strID
    End Sub


    Public Overrides Function ToString() As String
        Return Text
    End Function
End Class

Now If I do

Me.cbHomeDrive.SelectedText = "E:"

right after

Me.cbHomeDrive.Enabled = False

Then nothing happens, and the combobox shows as Z:.

If instead of

Me.cbHomeDrive.SelectedText = "E:"

I use

SetComboBoxToTextIndex(Me.cbHomeDrive, "E:")

with

' WTF '
' http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedtext.aspx '
Sub SetComboBoxToTextIndex(ByVal cbThisComboBox As ComboBox, ByVal strItemText As String)

    For i As Integer = 0 To cbThisComboBox.Items.Count - 1 Step 1
        If StringComparer.OrdinalIgnoreCase.Equals(cbThisComboBox.Items(i).ToString(), strItemText) Then
            cbThisComboBox.SelectedIndex = i
            Exit For
        End If
    Next

End Sub

Then it sets the correct selected item (E:).

Why does it not work with Me.cbHomeDrive.SelectedText = “E:”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:02:49+00:00Added an answer on May 20, 2026 at 8:02 pm

    I think you’re misunderstanding what the SelectedText property is, refer to the MSDN documentation.

    The SelectedText property is not the item from the list of items, it’s the portion of an editable combobox that is selected, as if you were doing a copy/paste type of selection.

    Your SetComboBoxToTextIndex method is the proper way to find and select an item in the list. Aternatively, if your ComboBoxItem properly implements Equals, you can find the appropriate instance and set the SelectedItem property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about combobox.I use visual c# and I want to insert
Question: How do you set the binding for a ComboBox's Selected items to one
The problems is simple: when ItemsSource is updated Combobox doesn't refresh e.g. new items
I've written a code for filtering items in ComboBox: My question is, how would
Question Using XSLT 1.0, given a string with arbitrary characters how can I get
I currently use this style for my ComboBox in WPF: <Style TargetType=ComboBox> <Setter Property=Foreground
I am dynamically creating a combobox like this: public Control GenerateList(Question question) { //
I want to implement the following combobox in ExtJS. The question is, how to
Question : Most code samples on the DataGridComboBox seem to use a static resource
The question is very simple, How to insert ComboBox selected item into ListBox using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.