4 Replies - 9301 Views - Last Post: 21 May 2012 - 04:01 PM Rate Topic: -----

#1 BJseal91  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • Joined: 18-April 09

How to change listview selected row back color

Posted 21 May 2012 - 05:36 AM

Hi Team Of Programmers,
I need your help of a problem that is frustrating me I have a list view box and I want to change to full row select back colour I have already achieved this for list box but the settings are different this is what I am wanting to do for list view any help will be gratefully taken on board

Posted Image

Code:
    Private Sub listBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
            Dim clrSelectedText As Color = Color.Black 'Our color for selected(text)
            Dim clrHighlight As Color = Color.LightGreen 'Our background for selected items
            If e.State = DrawItemState.Selected Then
                'This item is selected
                'e.DrawBackground()
                e.Graphics.FillRectangle(New SolidBrush(clrHighlight),
                e.Bounds) 'Fill the item's rectangle with our highlight
                e.Graphics.DrawString(ListBox1.Items.Item(e.Index),
                e.Font, New SolidBrush(clrSelectedText), e.Bounds) 'Draw the text for the item
            ElseIf e.State = DrawItemState.None Then
                'This item has no state
                e.DrawBackground() 'Draw our regular background
                e.Graphics.DrawString(ListBox1.Items.Item(e.Index),
                e.Font, Brushes.Black, e.Bounds) 'Draw the item text in its regular(color)
            End If
            'Draws a focus rectangle around the item if it has focus
            e.DrawFocusRectangle()
        End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: How to change listview selected row back color

#2 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 400
  • Joined: 08-January 12

Re: How to change listview selected row back color

Posted 21 May 2012 - 05:59 AM

So you want a program like this but instead using a listview control?
Was This Post Helpful? 0
  • +
  • -

#3 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 400
  • Joined: 08-January 12

Re: How to change listview selected row back color

Posted 21 May 2012 - 06:07 AM

The Easy Way
Okay it seems the best solution for listview is to set the Listview.HideSelection = True and then the backcolor will become the selected color. Because the selected color overrides the background color, it needs to be turned off. You will then also have to add a picture box and set the listview's .picture property to the picture box to get the color. Also the listview will have to be in tiled arrangement. This should make things easy for you.

Not So Easy
otherwise you will have to subclass and use API's

I would also like to think that it is still possible in VB to create your own controls. It believe it is even possible to edit a existing control. The downside is getting rights for the controls you create.

This post has been edited by Toadill: 21 May 2012 - 06:21 AM

Was This Post Helpful? 0
  • +
  • -

#4 BJseal91  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • Joined: 18-April 09

Re: How to change listview selected row back color

Posted 21 May 2012 - 03:24 PM

View PostToadill, on 21 May 2012 - 07:07 AM, said:

The Easy Way
Okay it seems the best solution for listview is to set the Listview.HideSelection = True and then the backcolor will become the selected color. Because the selected color overrides the background color, it needs to be turned off. You will then also have to add a picture box and set the listview's .picture property to the picture box to get the color. Also the listview will have to be in tiled arrangement. This should make things easy for you.

Not So Easy
otherwise you will have to subclass and use API's

I would also like to think that it is still possible in VB to create your own controls. It believe it is even possible to edit a existing control. The downside is getting rights for the controls you create.


Yes that was right Thank you for you answers I will give that ago

Kind Regards
Was This Post Helpful? 0
  • +
  • -

#5 Toadill  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 400
  • Joined: 08-January 12

Re: How to change listview selected row back color

Posted 21 May 2012 - 04:01 PM

Glad to help! hope it works out for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1