Solved

Change row color in Listview control

Posted on 2003-10-30
8
1,658 Views
Last Modified: 2008-10-09
Hi,
Any help?
How can a change the color of row in listview control in vb.net??

Cheer's
Arshad
0
Comment
Question by:arshadkhan
  • 4
  • 2
  • 2
8 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 9650941
Dim selectedItem As ListViewItem
    For Each selectedItem In ListView1.SelectedItems
      selectedItem.BackColor = myColor
    Next

0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9650987
 
        ' Set the view to show details.
        ListView1.View = View.Details
        ' Allow the user to edit item text.
        ListView1.LabelEdit = True
        ' Allow the user to rearrange columns.
        ListView1.AllowColumnReorder = True
        ' Display check boxes.
        ListView1.CheckBoxes = True
        ' Select the item and subitems when selection is made.
        ListView1.FullRowSelect = True
        ' Display grid lines.
        ListView1.GridLines = True
        ' Sort the items in the list in ascending order.
        ListView1.Sorting = SortOrder.Ascending

        ' Create three items and three sets of subitems for each item.
        Dim item1 As New ListViewItem("item1", 0)
        ' Place a check mark next to the item.
        item1.Checked = True
        item1.SubItems.Add("1")
        item1.SubItems.Add("2")
        item1.SubItems.Add("3")
        Dim item2 As New ListViewItem("item2", 1)
        item2.SubItems.Add("4")
        item2.SubItems.Add("5")
        item2.SubItems.Add("6")
        Dim item3 As New ListViewItem("item3", 0)
        ' Place a check mark next to the item.
        item3.Checked = True
        item3.SubItems.Add("7")
        item3.SubItems.Add("8")
        item3.SubItems.Add("9")

        ListView1.View = View.Details

        'Add the items to the ListView.
        ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

'give colors to the first listView item
dim lv  as new ListViewItem
lv = listView1.Items(0)
               
lv.BackColor  = Color.Chocolate
lv.ForeColor  = Color.LemonChiffon
               
'give colors to the 2nd listView item
lv = listView1.Items(1)

'show subitems in differnt colors
lv.UseItemStyleForSubItems = false
               
dim lvs  as new  ListViewItem.ListViewSubItem()
'change color of the 2nd subitem of the 2nd listview item
lvs = lv.SubItems(1)
               
'colors of the listview item
lv.BackColor  = Color.DarkKhaki
lv.ForeColor  = Color.DarkGreen
lv.Font = new Font("Arial",12.0,FontStyle.Bold )

'colors of the listview subitem
lvs.BackColor = Color.CornflowerBlue
lvs.ForeColor = Color.White

0
 

Author Comment

by:arshadkhan
ID: 9651044
thanks for quick response,

if the column value =blabla then change the row color to red

can you be more clear

Thanks
Arshad

0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9651104
Private Sub ChangeRowClor(Ind as Integer)

     dim lv  as new ListViewItem
     lv = listView1.Items(Ind)

     Lv.BackColor = Color.Red
End Sub

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 28

Expert Comment

by:iboutchkine
ID: 9651157
That is exactly whote I wrote above
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9651185
i dont think so....
0
 

Author Comment

by:arshadkhan
ID: 9651197
thanks for quick response.

Private Sub ChangeRowClor(Ind as Integer)

     dim lv  as new ListViewItem
     lv = listView1.Items(Ind)

     Lv.BackColor = Color.Red
End Sub

what is (Ind) here ??
is it a row position ??

thanks
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 50 total points
ID: 9651283
Yeah the item index
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now