Solved

Change row color in Listview control

Posted on 2003-10-30
8
1,684 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
Stressed Out?

Watch some penguins on the livecam!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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