View Single Post
  #1 (permalink)  
Old November 3rd, 2003, 08:08 PM
MichaelTJ MichaelTJ is offline
Authorized User
 
Join Date: Oct 2003
Location: , , Norway.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default listbox, different color for each item?

Hi all,
I was just wondering if it's possible to change the text color or background color for an item in a listbox? Eks. you have an SQL querry string that gets some values. If one of the values is 1 then the color is normal. If the value is 2 then the color turns red! Is this possible?

***************MY CODE FOR FILLING THE LISTBOX********
    Sub FillList(ByVal Level As Int32, ByVal SQL1 As String)
        Dim SQ As Data.SqlClient.SqlDataReader
        Dim SQLConnect As Data.SqlClient.SqlConnection
        SQLConnect = SQL.Connect
        Dim SQLCmd As New System.Data.SqlClient.SqlCommand("set dateformat dmy", SQLConnect)
        ListColl(Level).Items.Clear()
        Try
            SQLCmd.CommandText = (SQL1)
            SQ = SQLCmd.ExecuteReader()
            Dim i As Integer
            Do While SQ.Read = True
                If SQ.GetString(0).Trim <> "" Then ListColl(Level).Items.Add(SQ.GetString(0))
            Loop
            SQ.Close()
        Catch ex As Exception
            Response.Write("Fill list: " & ex.Message)
        End Try
        SQLCmd.Connection.Close()
        SQLConnect.Close()
    End Sub
************END CODE*********************

I need something like this:
************CODE FROM ABOVE*********
Do While SQ.Read = True
If SQ(2) = 1 then
If SQ.GetString(0).Trim <> "" Then ListColl(Level).Items.Add(SQ.GetString(0))
else
*Some Color setting for that item*
If SQ.GetString(0).Trim <> "" Then ListColl(Level).Items.Add(SQ.GetString(0))
end if
Loop
***************END******************

Thanks for any help I can get on this!

------------------------
All help is Good help!
Regards
Michael
__________________
------------------------
All help is Good help!
Regards
Michael
Reply With Quote