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
Printable View
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
There is no ListItem. It should be ListViewItem. You cant add a ListViewItem to a combobox.
You can add item like this:
VB Code:
comboBox1.Items.Add("Whatever you want")
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?
OH Sorry! it was my mistake!
sorry for the trouble. There was another class names listBox in that code!.
:D