Results 1 to 4 of 4

Thread: ListItem

  1. #1

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117

    ListItem

    hi
    how can i declare a listitem for adding items for a comboBox.

    while writing like this
    Dim objListItem as ListItem
    I'm getting a blue underline under ListItem

    i've imported system.data and system.data.sqlclient

    please help
    when in doubt, win the trick

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    There is no ListItem. It should be ListViewItem. You cant add a ListViewItem to a combobox.

    You can add item like this:
    VB Code:
    1. comboBox1.Items.Add("Whatever you want")
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    Hi DvGrp

    Thanks for your reply. But I got the following code from microsoft's site and it works perfectly. but if start a new project and try to declare listitem, I'm getting an error.

    code from the site
    Private Sub PopulateProductList()
    ' This procedure populates the list box on the
    ' form with a list of available products from the
    ' Northwind database.

    Dim cnSQL As SqlConnection
    Dim cmSQL As SqlCommand
    Dim drSQL As SqlDataReader
    Dim strSQL As String
    Dim objListItem As ListItem

    Try
    ' Build Select statement to query product names from the products
    ' table.
    strSQL = "SELECT ProductName, ProductID FROM Products"

    cnSQL = New SqlConnection(ConnectionString)
    cnSQL.Open()

    cmSQL = New SqlCommand(strSQL, cnSQL)
    drSQL = cmSQL.ExecuteReader()

    lstProducts.Items.Clear()

    ' Loop through the result set using the datareader class.
    ' The datareader is used here because all that is needed
    ' is a forward only cursor which is more efficient.
    Do While drSQL.Read()
    objListItem = New ListItem(drSQL.Item("ProductName").ToString(), _
    CInt(drSQL.Item("ProductID")))
    lstProducts.Items.Add(objListItem)
    Loop

    If lstProducts.Items.Count > 0 Then
    lstProducts.SetSelected(0, True)
    End If

    ' Close and Clean up objects
    drSQL.Close()
    cnSQL.Close()
    cmSQL.Dispose()
    cnSQL.Dispose()

    Catch e As SqlException
    MsgBox(e.Message, MsgBoxStyle.Critical, "SQL Error")

    Catch e As Exception
    MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
    End Try
    End Sub

    why is this?
    when in doubt, win the trick

  4. #4

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    OH Sorry! it was my mistake!
    sorry for the trouble. There was another class names listBox in that code!.

    when in doubt, win the trick

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