Home All Groups Group Topic Archive Search About
Author
26 May 2006 12:52 AM
Mike Johnson
I'm using VS Basic.net 2003
How can I change the foreground color of the item being added to a listbox?

Author
26 May 2006 10:16 AM
Cor Ligthert [MVP]
Mike,

You mean probably one by one, AFAIK you cannot, without not creating your
own listbox. And even than I am not sure.

Cor

Show quoteHide quote
"Mike Johnson" <MikeJohn***@discussions.microsoft.com> schreef in bericht
news:B6BD0D2C-7A61-4962-8B16-39082D9CAF6D@microsoft.com...
> I'm using VS Basic.net 2003
> How can I change the foreground color of the item being added to a
> listbox?
Author
26 May 2006 11:42 AM
Herfried K. Wagner [MVP]
"Mike Johnson" <MikeJohn***@discussions.microsoft.com> schrieb:
> I'm using VS Basic.net 2003
> How can I change the foreground color of the item being added to a
> listbox?

You may want to use either a listview control in details or list mode or a
treeview control instead of the standard listbox control.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
26 Jul 2006 8:18 PM
Mike Johnson
Herfried , I took your suggestion and changed over to ListView instead of
listbox. But I'm still having a problem. Please help. Thanks

I have the following code below. The objective is to change the forecolor of
the item if the item being added is different from the last item. Well it's
not working. When I step thru the code it's going to the correct areas when
the lastitem not equal to current item but it's not changing the foreground
color. Any ideas why. Thanks

Do
                line = sr.ReadLine()
                If line Is Nothing Then
                Else
                    If LastItem <> ListItem(line) Then
                        LastItem = ListItem(line)
                        ListView1.ForeColor = Color.Red
                        ListView1.Items.Add(line)
                    Else
                        LastItem = ListItem(line)
                        ListView1.Items.Add(line)
                    End If
                End If
                ListView1.ForeColor = Color.Black
            Loop While Not line Is Nothing


Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Mike Johnson" <MikeJohn***@discussions.microsoft.com> schrieb:
> > I'm using VS Basic.net 2003
> > How can I change the foreground color of the item being added to a
> > listbox?
>
> You may want to use either a listview control in details or list mode or a
> treeview control instead of the standard listbox control.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
26 Jul 2006 9:14 PM
Mike Johnson
Herfried, I got the background color working but for some reason it want show
up until the form is redrawn the control is on. The new code is below. Thanks

Do
                line = sr.ReadLine()
                first = first + 1
                If line Is Nothing Then
                Else
                    If first <> 1 Then
                        'If this is the second pass and > items are then
added from here
                        If LastItem <> ListItem(line) Then
                            LastItem = ListItem(line)
                            ListView1.Items.Add(line).BackColor =
Color.LightBlue
                            ListView1.Update()
                            Me.Refresh()
                        Else
                            LastItem = ListItem(line)
                            ListView1.Items.Add(line).BackColor = Color.White
                            ListView1.Update()
                            Me.Refresh()
                        End If
                    Else
                        'If first occurance then item is added from here
                        LastItem = ListItem(line)
                        ListView1.Items.Add(line).BackColor = Color.White

                    End If
                End If
            Loop While Not line Is Nothing

Show quoteHide quote
"Mike Johnson" wrote:

> Herfried , I took your suggestion and changed over to ListView instead of
> listbox. But I'm still having a problem. Please help. Thanks
>
> I have the following code below. The objective is to change the forecolor of
> the item if the item being added is different from the last item. Well it's
> not working. When I step thru the code it's going to the correct areas when
> the lastitem not equal to current item but it's not changing the foreground
> color. Any ideas why. Thanks
>
> Do
>                 line = sr.ReadLine()
>                 If line Is Nothing Then
>                 Else
>                     If LastItem <> ListItem(line) Then
>                         LastItem = ListItem(line)
>                         ListView1.ForeColor = Color.Red
>                         ListView1.Items.Add(line)
>                     Else
>                         LastItem = ListItem(line)
>                         ListView1.Items.Add(line)
>                     End If
>                 End If
>                 ListView1.ForeColor = Color.Black
>             Loop While Not line Is Nothing
>
>
> "Herfried K. Wagner [MVP]" wrote:
>
> > "Mike Johnson" <MikeJohn***@discussions.microsoft.com> schrieb:
> > > I'm using VS Basic.net 2003
> > > How can I change the foreground color of the item being added to a
> > > listbox?
> >
> > You may want to use either a listview control in details or list mode or a
> > treeview control instead of the standard listbox control.
> >
> > --
> >  M S   Herfried K. Wagner
> > M V P  <URL:http://dotnet.mvps.org/>
> >  V B   <URL:http://classicvb.org/petition/>
> >
> >