473,395 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

owner drawn problem

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
Apr 25 '06 #1
0 1391

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James | last post by:
Is there a way to Owner drawn tray context menu ? - I know that there is a bug with the custom drawing of a context menu assigned to a tray icon - but I was hoping someone could advise me as to how...
1
by: boxim | last post by:
hi all, i need to develop a control to show contact details for companies, in a similar fashion to the way outlook shows contacts. at the moment, i'm cheating using HTML fed from a web server,...
2
by: Eric | last post by:
I implemented owner drawing on the main and context menus of my main form. It works fine. There is also a notify icon control that has a context menu. When the icon is in the status bar, it...
1
by: Michael C | last post by:
Anyone know if there are some code samples out there of owner-drawn buttons? Specifically I'm trying to create .NET IDE style buttons for a form. Thanks, Michael C.
1
by: Patty O'Dors | last post by:
Hi I have some code to create an ownerdrawn listbox (derived), and when I add an item to it, the bold text of the first item (the title, 'Collections and Maturities') mysteriously seems to get...
2
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I...
0
by: Brian Henry | last post by:
Ok whats going on here... got a couple problems... this is relevant now to this group since .NET 2.0 is finally RTM 1) draws really slow when making it a large form (resizing speed is jerky) to...
0
by: Steve Marshall | last post by:
Hi All, I'm working on an owner-drawn combo box which will display multiple columns in the list, either from a table in an associated DataSourse or from delimited strings in the Items...
0
by: LostInMd | last post by:
Hi All, I've got an owner drawn listBox where I draw and measure the items that I add to the listBox. For example, I have a listBox that can only display 10 characters on each horizontal line. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.