I cant seem to remember this one... I have a list view, and im owner drawing
the items, i dont want the selection to hide when it loses focus so i have
hideselection = false, but when i owner draw this all the items come up gray
instead of just the one that is selected when focus is lost, the blue one
shows up correctly when it has focus... any help on this would be great... i
need to do most of my drawing in the sub items drawing because of how my
control is structured..
here is an example, im trying to get it to act like a list view does when
its not owner drawn, so i can customize it later after i get this working
correctly
Public Class Form1
Private Sub ListView1_DrawColumnHeader(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawListViewColumnHeaderEvent Args) Handles
ListView1.DrawColumnHeader
e.DrawDefault = True
End Sub
Private Sub ListView1_DrawSubItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawListViewSubItemEventArgs) Handles
ListView1.DrawSubItem
' e.Graphics.FillRectangle(Drawing.SystemBrushes.Hig hlight, e.Bounds)
' ControlPaint.DrawFocusRectangle(e.Graphics, e.Item.Bounds,
Drawing.SystemColors.WindowText, Drawing.SystemColors.Highlight)
Debug.WriteLine(e.ItemIndex & ":" & e.ItemState.ToString)
If (e.ItemState And ListViewItemStates.Selected) =
ListViewItemStates.Selected Then
If (e.ItemState And ListViewItemStates.Focused) = ListViewItemStates.Focused
Then
' FOCUSED AND SELECTED
e.Graphics.FillRectangle(Drawing.SystemBrushes.Hig hlight, e.Bounds)
ControlPaint.DrawFocusRectangle(e.Graphics, e.Item.Bounds,
Drawing.SystemColors.WindowText, Drawing.SystemColors.Highlight)
Else
' JUST SELECTED
e.Graphics.FillRectangle(Drawing.SystemBrushes.Con trol, e.Bounds)
End If
' ELSE NOT SELECTED
Else
e.Graphics.FillRectangle(Drawing.SystemBrushes.Win dow, e.Bounds)
End If
e.DrawText()
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.Des ignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New
System.Windows.Forms.ListViewItem("dfhfdh")
Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New
System.Windows.Forms.ListViewItem("56h56h")
Dim ListViewItem3 As System.Windows.Forms.ListViewItem = New
System.Windows.Forms.ListViewItem("54h45h")
Me.ListView1 = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader()
{Me.ColumnHeader1, Me.ColumnHeader2})
Me.ListView1.FullRowSelect = True
Me.ListView1.HideSelection = False
Me.ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem()
{ListViewItem1, ListViewItem2, ListViewItem3})
Me.ListView1.Location = New System.Drawing.Point(0, 0)
Me.ListView1.Name = "ListView1"
Me.ListView1.OwnerDraw = True
Me.ListView1.Size = New System.Drawing.Size(241, 168)
Me.ListView1.TabIndex = 0
Me.ListView1.UseCompatibleStateImageBehavior = False
Me.ListView1.View = System.Windows.Forms.View.Details
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(94, 211)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.ListView1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Friend WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Friend WithEvents Button1 As System.Windows.Forms.Button
End Class