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

How to override listbox click?

I'm drawing my own inherited listbox, and I don't want the user
to select any items, but I do want to allow them to scroll the listbox.

When they click on an item, there is a flicker of the previously
selected item and the new selected item. Even though I don't
show anything selected, the default behaviour wants to redraw
those items.

What can I do to stop the user click from selecting an item in
the list?

LFS
Nov 20 '05 #1
9 2083
Larry,
Are you using the OwnderDraw overrides? (OnItemDraw, for example)
If so, are you painting the background rectangle before drawing the text?
If you give me a few details, I can give you a better answer.

-Rob Teixeira [MVP]

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
I'm drawing my own inherited listbox, and I don't want the user
to select any items, but I do want to allow them to scroll the listbox.

When they click on an item, there is a flicker of the previously
selected item and the new selected item. Even though I don't
show anything selected, the default behaviour wants to redraw
those items.

What can I do to stop the user click from selecting an item in
the list?

LFS

Nov 20 '05 #2
This will prevent all LButton Clicks

Private Const WM_LBUTTONDOWN As Integer = &H20

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message
If m.Msg = WM_LBUTTONDOWN Then Exit Su
MyBase.WndProc(m
End Sub
Nov 20 '05 #3

"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote
Larry,
Are you using the OwnderDraw overrides? (OnItemDraw, for example)
If so, are you painting the background rectangle before drawing the text?
If you give me a few details, I can give you a better answer.
Yes, I've set the DrawMode to DrawMode.OwnerDrawVariable

I am overriding OnMeasureItem and OnDrawItem. In the OnDrawItem
I draw my own background as well as the stuff I want listed. When I add
an item, the control seems to erase everything in the list, and then loop
through the items to get them drawn. It would be nice to avoid that
invalidate process and just go ahead with the painting.
Also, when the user clicks on one of the items in the list, then that one,
and the one that was previously selected get erased, and called to be
redrawn. That is causing flicker for every click that changes the selected
item. There is no difference between a selected item, and the others, its
just that the listbox is keeping track of the ListIndex and erasing the ones
that would be changing. I would like to make that list non-clickable, but
I do want to allow them to scroll the list.

I was thinking I need to stop the click from getting through. I tried
setting SelectionMode to None, but the listbox still keeps track of the
ListIndex and acts as before. I tried overriding OnPaintBackground,
but that didn't get it....

In simple terms it is invalidating sections that I don't want invalidated.
Really all I want to allow them to use is the scroll bar.

LFS






-Rob Teixeira [MVP]

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
I'm drawing my own inherited listbox, and I don't want the user
to select any items, but I do want to allow them to scroll the listbox.

When they click on an item, there is a flicker of the previously
selected item and the new selected item. Even though I don't
show anything selected, the default behaviour wants to redraw
those items.

What can I do to stop the user click from selecting an item in
the list?

LFS


Nov 20 '05 #4

"Whatshisname" <an*******@discussions.microsoft.com> wrote
This will prevent all LButton Clicks.

Private Const WM_LBUTTONDOWN As Integer = &H201

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_LBUTTONDOWN Then Exit Sub
MyBase.WndProc(m)
End Sub

Thanks, that did work for stopping user clicks. I am still wondering
how to stop the control from invalidating (painting over) sections of
the control.

LFS
Nov 20 '05 #5
I'm not sure if this will make it better but it's worth a shot

Private Const WM_LBUTTONDOWN As Integer = &H20
Private Const WM_ERASEBKGND As Integer = &H1

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message
If m.Msg = WM_LBUTTONDOWN Or m.Msg = WM_ERASEBKGND Then Exit Su
MyBase.WndProc(m
End Su

Nov 20 '05 #6
* "Larry Serflaten" <se*******@usinternet.com> scripsit:
I'm drawing my own inherited listbox, and I don't want the user
to select any items, but I do want to allow them to scroll the listbox.

When they click on an item, there is a flicker of the previously
selected item and the new selected item. Even though I don't
show anything selected, the default behaviour wants to redraw
those items.

What can I do to stop the user click from selecting an item in
the list?


<URL:http://dotnet.mvps.org/dotnet/samples/controls/downloads/LockListBox.zip>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7

"Whatshisname" <an*******@discussions.microsoft.com> wrote
I'm not sure if this will make it better but it's worth a shot.

Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_ERASEBKGND As Integer = &H14

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_LBUTTONDOWN Or m.Msg = WM_ERASEBKGND Then Exit Sub
MyBase.WndProc(m)
End Sub


That masks the symptoms, and I'll use it until something better comes along, but
I'd prefer to stop it at its source. IE, I'd rather the message would never get sent....

Thanks!
LFS

Nov 20 '05 #8
Personally, I would rather write my own listbox rather than trying to muscle Microsofts listbox. That way, I have total control of what it's doing and why it's doing it. It wouldn't take that much code to write. Draw a border, add an array list, then add a scrollbar and use the API ScrollWindow to scroll the items up and down. Piece of cake. But then thats all I do, write controls.
Nov 20 '05 #9
I am not sure that recreating old functionality is productive way - except
when learning to program. So, I have question - why KeyDown and KepPressed
events are not suitable?

HTH
Alex

"Whatshisname" <an*******@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
Personally, I would rather write my own listbox rather than trying to

muscle Microsofts listbox. That way, I have total control of what it's doing
and why it's doing it. It wouldn't take that much code to write. Draw a
border, add an array list, then add a scrollbar and use the API ScrollWindow
to scroll the items up and down. Piece of cake. But then thats all I do,
write controls.
Nov 20 '05 #10

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

Similar topics

5
by: Bill | last post by:
I have have two list boxes. One is a listing of all possible variables. We'll call this listbox A. The other is a listing of all the selected variables. We'll call this listbox B. If a person...
5
by: Darius | last post by:
I'm writing here in hopes that someone can explain the difference between the new and virtual/override keywords in C#. Specifically, what is the difference between this: public class Window {...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
13
by: Larry Woods | last post by:
I am creating a "from-to" set of listboxes where the "left" listbox had a list of values and I want to be able to select these values, 1 at a time, and move them into a "right" listbox, removing...
1
by: tony | last post by:
Hello! If you drag a ListBox into a windowform and then right click on this ListBox and then chose property. When you have the properties up click on the flash symbol for seeing all the events...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.