Solved

Change row color in Listview control

Posted on 2003-10-30
8
1,667 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
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.

 
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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

825 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