473,385 Members | 1,927 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,385 software developers and data experts.

My owner draw list box contorl doesn't "invalidate" old selected items!

Hi ppl,

My owner draw list box controls do not "refresh" old selected items when a
new selection is made. This means that as you click to make selections, the
previously selected items stay highlighted along with the new ones too. It
draws correctly when I minimize the window and then maximise it again, but I
just don't seem to be getting a "DrawItem" event for switching of an item
from Selected to NotSelected! Any ideas???

Here is the code I use:

Private Sub ListBox_DrawItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox.DrawItem

' Guard

If e.Index < 0 Then
Exit Sub
End If

' Get the object we wish to draw

Dim theItem As DataThumbnailViewItem = CType(ListBox.Items()(e.Index),
DataThumbnailViewItem)

' and render it.

If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
theItem.Render(e.Graphics, e.Bounds, True)
Else
theItem.Render(e.Graphics, e.Bounds, False)
End If
End Sub

and the code in the DataThumbnailViewItem render is something like:

' If selected, draw box border in selected colour

If bIsSelected Then
theGraphics.FillRectangle(System.Drawing.SystemBru shes.Highlight,
theBounds)
Else
theGraphics.FillRectangle(System.Drawing.SystemBru shes.Window,
theBounds)
End If
Nov 20 '05 #1
1 3537
Hi,

Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem

Dim g As Graphics = e.Graphics

Dim s As String

Dim d As Date

Dim br As Brush = SystemBrushes.WindowText

Dim brBack As Brush

Dim rDraw As Rectangle

Dim bSelected As Boolean = CBool(e.State And DrawItemState.Selected)

rDraw = e.Bounds

rDraw.Inflate(-1, -1)

If bSelected Then

brBack = Brushes.LightBlue

g.FillRectangle(Brushes.LightBlue, rDraw)

g.DrawRectangle(Pens.Blue, rDraw)

Else

brBack = Brushes.White

g.FillRectangle(brBack, e.Bounds)

End If

br = Nothing

brBack = Nothing

rDraw = Nothing

Try

s = ListBox1.Items.Item(e.Index).ToString

Catch

s = ""

End Try

Dim x, y As Integer

x = e.Bounds.Left + 25

y = e.Bounds.Top + 1

Dim c As Color

Dim b As SolidBrush

c = Color.FromName("Red")

b = New SolidBrush(c)

g.FillRectangle(b, x - 20, y + 2, 8, 8)

g.DrawString(s, ListBox1.Font, Brushes.Black, x, y)

End Sub

Ken

-----------------------

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:bv*******************@news.demon.co.uk...
Hi ppl,

My owner draw list box controls do not "refresh" old selected items when a
new selection is made. This means that as you click to make selections,
the
previously selected items stay highlighted along with the new ones too.
It
draws correctly when I minimize the window and then maximise it again, but
I
just don't seem to be getting a "DrawItem" event for switching of an item
from Selected to NotSelected! Any ideas???

Here is the code I use:

Private Sub ListBox_DrawItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox.DrawItem

' Guard

If e.Index < 0 Then
Exit Sub
End If

' Get the object we wish to draw

Dim theItem As DataThumbnailViewItem = CType(ListBox.Items()(e.Index),
DataThumbnailViewItem)

' and render it.

If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
theItem.Render(e.Graphics, e.Bounds, True)
Else
theItem.Render(e.Graphics, e.Bounds, False)
End If
End Sub

and the code in the DataThumbnailViewItem render is something like:

' If selected, draw box border in selected colour

If bIsSelected Then
theGraphics.FillRectangle(System.Drawing.SystemBru shes.Highlight,
theBounds)
Else
theGraphics.FillRectangle(System.Drawing.SystemBru shes.Window,
theBounds)
End If

Nov 20 '05 #2

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

Similar topics

6
by: Tim Conkling | last post by:
Ok, so if I want to selectively delete items from a sequence like a deque or vector from a for loop, I have to do something like this: for(iter = list.begin(); iter != list.end(); ++iter) {...
6
by: Arne Claus | last post by:
Hi If've just read, that remove() on a list does not actually remove the elements, but places them at the end of the list (according to TC++STL by Josuttis). It also says, that remove returns a...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
2
by: Serge Klokov | last post by:
Hi! 1. Please, help with example "paint on form by mouse" 2. Below is my example, but it clear the line after each Refresh()... how to fix? 3. How to draw the line in Mouse_Move event? ...
2
by: Simon Verona | last post by:
If I have a combobox set enabled=false then by default it will have dark grey text on a grey background. I want it to show as blue on white. I'm trying code such as : combobox.enabled=false...
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:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
4
by: pcnerd | last post by:
I've been playing with "classic" VB since version 3. I have VB6 Learning Edition. Recently, I wanted to try VB.NET. I got a beginner's book with a CD with the software & installed it. There are...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.