P
Paul Sullivan
Hi folks. I was hoping that someone can help me out here.
I am adding items to a listbox from a database. So far, I've had no
problems. However, when I try to use the SetSelected method and there
is only one item in the list box (who's index is 0), it won't highlight
(or at least, it doesn't show it on the screen).
Here my relevant code:
' Load Product List
dbQuery = "SELECT fullname FROM product_version_view ORDER BY fullname"
Dim dbProductCommand As New SqlClient.SqlCommand(dbQuery,
Me.KBConnection)
Dim dbProductReader As SqlClient.SqlDataReader
dbProductReader = dbProductCommand.ExecuteReader
Do While dbProductReader.Read
Me.ProductList.Items.Add(dbProductReader.Item("fullname").ToString)
Loop
dbProductReader.Close()
dbProductCommand.Dispose()
[... do other stuff ...]
' Select Products
dbQuery = "SELECT fullname FROM article_product_view WHERE kbid = " &
Me.kbid
Dim dbSProductCommand As New SqlClient.SqlCommand(dbQuery,
Me.KBConnection)
Dim dbSProductReader As SqlClient.SqlDataReader
dbSProductReader = dbSProductCommand.ExecuteReader
Do While dbSProductReader.Read
cnt =
ProductList.FindStringExact(dbSProductReader.Item("fullname").ToString)
Me.ProductList.SetSelected(cnt, True)
Debug.WriteLine("Selecting index " & cnt)
Loop
dbSProductReader.Close()
dbSProductCommand.Dispose()
I even tried doing ProductList.SetSelected(0, True), but that didn't
seem to work either. And yes, the strings do match - if you look on
the debug window, it will say index 0 was selected, but not on the
screen.
Anyone out there have any ideas?
Thanks,
Paul
(e-mail address removed)
I am adding items to a listbox from a database. So far, I've had no
problems. However, when I try to use the SetSelected method and there
is only one item in the list box (who's index is 0), it won't highlight
(or at least, it doesn't show it on the screen).
Here my relevant code:
' Load Product List
dbQuery = "SELECT fullname FROM product_version_view ORDER BY fullname"
Dim dbProductCommand As New SqlClient.SqlCommand(dbQuery,
Me.KBConnection)
Dim dbProductReader As SqlClient.SqlDataReader
dbProductReader = dbProductCommand.ExecuteReader
Do While dbProductReader.Read
Me.ProductList.Items.Add(dbProductReader.Item("fullname").ToString)
Loop
dbProductReader.Close()
dbProductCommand.Dispose()
[... do other stuff ...]
' Select Products
dbQuery = "SELECT fullname FROM article_product_view WHERE kbid = " &
Me.kbid
Dim dbSProductCommand As New SqlClient.SqlCommand(dbQuery,
Me.KBConnection)
Dim dbSProductReader As SqlClient.SqlDataReader
dbSProductReader = dbSProductCommand.ExecuteReader
Do While dbSProductReader.Read
cnt =
ProductList.FindStringExact(dbSProductReader.Item("fullname").ToString)
Me.ProductList.SetSelected(cnt, True)
Debug.WriteLine("Selecting index " & cnt)
Loop
dbSProductReader.Close()
dbSProductCommand.Dispose()
I even tried doing ProductList.SetSelected(0, True), but that didn't
seem to work either. And yes, the strings do match - if you look on
the debug window, it will say index 0 was selected, but not on the
screen.
Anyone out there have any ideas?
Thanks,
Paul
(e-mail address removed)