Results 1 to 4 of 4

Thread: problem with combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    11

    problem with combobox

    using mircosoft visual basic .net on smart application device,plaform is pocket pc..
    i tried using ' ComboBox2.Items.Insert(0, "-- Choose --") ' to make it as default,but it jjuz display my 1st record of my database..anyone idea why??

    Here's my code..
    Dim dsn As String
    Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    'determine which server and database to use
    dsn = "server = 198.0.0.91; uid=sa; pwd=; database=Boxoffice"
    Dim myConnection As SqlConnection = New SqlConnection()
    myConnection.ConnectionString = dsn
    Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from Book", myConnection)
    ' create a new dataset
    Dim ds As DataSet = New DataSet()
    ' fill dataset
    da.Fill(ds, "Book")

    ' Attach DataSet to ComboBox2

    ComboBox2.DataSource = ds.Tables(0)
    ComboBox2.DisplayMember = "Date"
    ComboBox2.Items.Insert(0, "-- Choose --")



    End Sub

  2. #2
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Doesn't work that way unfortunately, either you load your combobox yourself or you use a datasource, if the latter it uses the records in the dataset no matter what.

  3. #3
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Kryton

    Include the "-- Choose --" in the SELECT statement using a union.
    VB Code:
    1. Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT '-- Choose --' As date " _
    2.   & " UNION Select Date  from Book", myConnection)
    3. ' create a new dataset
    4. Dim ds As DataSet = New DataSet()
    5. ' fill dataset
    6. da.Fill(ds, "Book")
    7.  
    8. ' Attach DataSet to ComboBox2
    9.  
    10. ComboBox2.DataSource = ds.Tables(0)
    11. ComboBox2.DisplayMember = "Date"

    The select statement will expose a dataset with "-- Choose --" as the first item. Hope this works.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    11

    Smile

    thanks...but i've decided to load combobox myself ..ive tried all the code ,kept getting the same error whenever i add "ComboBox2.Items.Insert(0, "-- Choose --") " or
    ComboBox2.Items.Add(0, "-- Choose --")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width