Why is my tlistbox requiring me to double up my ampersands?

306 Views Asked by At

Is there a way to make it so you don't have to double up your &'s to make Delphi list box not register them as hotkeys?

We've got a list of drug names that we populate in a ListBox, some of the drugs have &'s in them like "A & D Ointment", well it's kind of dumb to have "A _D Ointment" show up so we double up the &&'s to make it "A & D Ointment" the only problem is, when we do that we can't us the text in the list box for anything useful without re-unconverting the text.

It would be must more convenient for us to just turn off the hotkey thing altogether which I can't seem to find a way to do with the IDE, but I'm sure there's some fancy windows message to override this (hopefully I don't have to override the base class)


We're overriding the DrawItem function using:

DrawText(List.Canvas.Handle, PChar(List.Items.Strings[Index]), -1, Rect, DT_VCENTER);
1

There are 1 best solutions below

5
On BEST ANSWER

You're probably not using the default TListBox draw function if this is happening as by default it uses DT_NOPREFIX to draw things.

Check and make sure you're not overriding the DrawItem function to see if use DrawText without DT_NOPREFIX. If you use DT_NOPREFIX, then your text will remain the same.