Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TListBox OnKeyPress behaviour

Status
Not open for further replies.

Griffyn

Programmer
Jul 11, 2002
1,077
AU
Hi all,

I'll skip my implementation and get straight to where my problem lies.

Put a TListBox on a form, give it some strings in it's Items property and run it. Give the ListBox the focus and press some keys - the selected item remains selected. Even if you capture the OnKeyPress and modify the value of the selected Item. This is the functionality I want.

However, my project needs the TListBox's Style property to be lbVirtual. The quick way of explaining this to the uninitiated is that the TListBox's strings that it displays are not stored in any of it's properties, and instead are provided by an OnData event, and must be displayed by an event linked to the OnDrawItem event. That part all works.

However, when I press a key - no matter which key - on my TListBox that's got it's Style property set to lbVirtual, it changes the ItemIndex to 0!

I've tried quite a few things, including overriding the KeyPress procedure, I've set the AutoComplete property to False, nothing seems to work. I'm using a descendant of TCustomListBox so I can play about a bit.

Anyone come up against this before? and how do I stop the ItemIndex from changing?

Using D6 Enterprise. Many thanks.
 
did you try capturing the WM_KEYDOWN event (onkeydown) and set the key value to 0??

--------------------------------------
What You See Is What You Get
 
Hi whosrdaddy,

yep. My implementation already overrides the KeyDown procedure and while it will call inherited in some cases, if I comment this out so that never does, it doesn't change anything.

I also override the KeyPress procedure and this doesn't call inherited either.

The selection changes the moment I press the key down and happens before I release it.

When I step through my code, I've watched ItemIndex to see when it changes. It gets through all my code unscathed and hits the OnDrawItem event still ok but after a few (may depend on how many items are visible), it suddenly changes to 0 on one of the passes.

Needless to say, I've got nothing in my code that would get called to do this.

I've also had a good look at the StdCtrls unit to see what within TListBox can set the ItemIndex to 0. The KeyPress procedure can, as well as the ClearSelection. Any more ideas?
 
Still haven't got anywhere with this. Has nobody here ever used a TListBox with a Style of lbVirtual?

How about... does anyone know of a way to trace into the StdCtrls unit while debugging?

I'm guessing this is compiled within the rtl60.bpl library. I don't want to muck anything up by trying to recompile this somehow with a new version of StdCtrls. Can anybody help there?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top