Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2007, 04:34 PM
Authorized User
 
Join Date: Dec 2006
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default pre-selecting an item in a combo box

I am working on a windows form to allow my users to search for a specific equipment number and display it's current information. If the information was entered incorrectly, the user will be allowed to update certain information.

The current information is displayed in read-only text boxes.
The information that will be able to be updated is in contained in combo boxes.
What I want to do is have the current value displayed in the combo box.

This is the code I have so far.
Code:
    Private Sub LoadLocationLookup()
        'using runtime DataSet and DataAdapters to load combo boxes
        Me.Cursor = Cursors.WaitCursor
        Dim strSQL As String
        If cmbFile.SelectedText = "APC" Then
            strSQL = _
                "SELECT LocationID, LocationName from APC_Location " + _
                "ORDER BY LocationName;"
        Else
            strSQL = _
                "SELECT LocationID, LocationName from RMA_Location " + _
                "ORDER BY LocationName;"
        End If
        ' connect to SQL Server
        Dim strConn As New SqlConnection(APC_WirelessConnectionString)
        strConn.Open()

        Dim daLocation As New SqlDataAdapter
        Dim cmdLocation As New SqlCommand(strSQL, strConn)
        Dim dsLocation As New DataSet
        Dim dvLocation As New DataView

        cmdLocation.CommandType = CommandType.Text
        daLocation.SelectCommand = cmdLocation

        'Try Catch Block for error checking
        Try
            daLocation.Fill(dsLocation)

            dvLocation = dsLocation.Tables(0).DefaultView

            With Me.cmbLocation
                .DataSource = dvLocation
                .DisplayMember = "LocationName"
                .ValueMember = "LocationID"
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString)
        End Try
        strConn.Close()
        Me.Cursor = Cursors.Default
    End Sub
I've found the FindString and FindStringExact properties, but I'm not sure how to use them to do what I want.

Thanks for any help you can give me.
Karen

 
Old July 12th, 2007, 07:33 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

hey karen,

try this code

Dim i As Int16

With cmb
  .Items.Add("ABC")
  .Items.Add("EFG")
  .Items.Add("HIJ")

  i = .FindStringExact("HIJ")
  .SelectedIndex = i
End With







Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Item in a Binded Combo Box prasanta2expert C# 2 April 21st, 2008 08:45 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Combo Box item from SQLDataadpter... to Datagrid venkikrao VB.NET 0 April 19th, 2006 08:57 PM
Problem Pre Selecting CheckBoxes in a CheckBoxLis sandersbr ASP.NET 1.0 and 1.1 Basics 2 August 13th, 2004 08:14 AM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.