change ListBox items color

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TF

    change ListBox items color

    Hi,
    Is there any way to change the text color of SOME of the
    ListBox(Windows Forms Control) items in VB.NET?

    TF
  • Anthony Fine

    #2
    Re: change ListBox items color

    TF,

    I don't know of an easy way to do it using a ListBox control, I typically do
    not use them, I would use a ListView control instead. This typically gives
    you more features anyway, not to mention a bit more cosmetic appeal
    (strictly my opinion). From what I have discovered using the ListBox
    control, you can only set the ForeColor for the entire control, not the
    individual items within the control. If you would like to use the ListView
    control instead, here some sample code to do what you wanted to do.

    Just drag a ListView control onto your form, or build it dynamically,
    whichever you prefer, and then add the following code:

    Private Sub BuildListView
    Dim i As Integer
    ListView1.View = View.Details
    ListView1.Colum ns.Add("Column1 ", 200, HorizontalAlign ment.Left)
    For i = 0 To 3
    Dim x As New ListViewItem
    Select Case i
    Case 0
    x.Text = "Red text goes here..."
    x.ForeColor = System.Drawing. Color.Red
    Case 1
    x.Text = "Blue text goes here..."
    x.ForeColor = System.Drawing. Color.Blue
    Case 2
    x.Text = "Green text goes here..."
    x.ForeColor = System.Drawing. Color.Green
    Case 3
    x.Text = "Black text goes here..."
    x.ForeColor = System.Drawing. Color.Black
    End Select
    ListView1.Items .Add(x)
    Next i
    End Sub

    Hope this helps,

    Anthony



    "TF" <faridt@coned.c om> wrote in message
    news:ae1ce536.0 401061106.14a40 410@posting.goo gle.com...[color=blue]
    > Hi,
    > Is there any way to change the text color of SOME of the
    > ListBox(Windows Forms Control) items in VB.NET?
    >
    > TF[/color]


    Comment

    • TF

      #3
      Re: change ListBox items color

      Thanks Anthony

      It helped me

      Comment

      Working...