Solved

Change row color in Listview control

Posted on 2003-10-30
8
1,647 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

20 Experts available now in Live!

Get 1:1 Help Now