Help with .Net combo box


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Help with .Net combo box

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Posts
    3

    Help with .Net combo box

    I have a combo box on a form called cboName, already populated with nine names. Nothing is visible in the text portion of the combo box yet. I only want the combo box enabled if the logged on user is one of the nine names. I want the code to loop thru the names and compare them to the logged on user and then enable or disable the combo box (as part of the form load, or very early in the code before the user gets to the combo box). What properties of the combo box do I use to get the text of the names that I originally added using Items.Add so that I can Loop through to compare to the name of the user? Some form of SelectedIndex? Some form of SelectedItem?

    I think I should use something like

    If cboName.XXX = GetUserName(gUserName) Then
    cboName.Enabled = True
    Else
    cboName.Enabled = False
    EndIf


    In this example, gUserName would be tjones, his login name to the system. Timothy Jones would be the corresponding name in the combo box which was added earlier in another part of the code, and which would be returned by the GetUserName function.

    But I cannot seem to get the XXX to come up with text name equal to the name (Timothy Jones) that I added with Items.Add. This has got to be simple, but I'm just missing it somewhere.

    Can anyone help me here?

    TIA for anything anyone can offer.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Code:
    Dim UserName As String = GetUserName(gUserName)
    For Each item As Object In cboName.Items
        If item.ToString = UserName Then
            cboName.SelectedItem = item
            Exit For
        End If
    Next
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. Searching records using a Combo box
    By Ernie in forum VB Classic
    Replies: 2
    Last Post: 02-04-2003, 02:12 PM
  2. Saving text to a db using combo list box
    By Patty_5 in forum VB Classic
    Replies: 0
    Last Post: 05-22-2001, 08:55 AM
  3. combo box and dblist controls
    By Juan in forum VB Classic
    Replies: 0
    Last Post: 01-27-2001, 12:17 AM
  4. Adding horizontal scroll bar to a combo box
    By Kevin McCormack in forum VB Classic
    Replies: 4
    Last Post: 07-20-2000, 04:14 PM
  5. Combo Box & Mouse
    By Jody Kelsch in forum authorevents.appleman
    Replies: 1
    Last Post: 04-10-2000, 06:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center