Solved

Change row color in Listview control

Posted on 2003-10-30
8
1,678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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
 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Open a link in vb.net 2 27
Visual Studio npm 1 29
Updating a single record in forEach using C#/Entity 7 26
Starting to use Git with Visual  Studio Online 1 24
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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