Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Case sensitive Listbox and ComboBox

142 views
Skip to first unread message

Igor Lychakov

unread,
Mar 13, 2001, 2:43:21 PM3/13/01
to
Hello:
Is there any way to make List/ComboBox is case sensitive.

Here is an example:
1. initialize box
AddString("AAA");
AddString("aaa");
2. Select aaa or AAA
3. Click again on the ComboBox's arrow to open its listbox
Result -> AAA item is always selected instead of corresponding aaa or
AAA.


Igor Lychakov

unread,
Mar 13, 2001, 3:17:56 PM3/13/01
to
Hello:
Is there any way to make List/ComboBox is case sensitive?

Here is what I mean:

Joseph M. Newcomer

unread,
Mar 13, 2001, 5:01:02 PM3/13/01
to
Subclass the listbox and override the search functions to be
case-sensitive. If you want case-senstive sorting, that is A..Z
precede a..z, you will have to do it as an owner-draw box and
implement OnCompareItem to get case-senstive comparisons. If you want
the default sorting {A,a}, {B, b} ... {Z, z} which I indicate here as
treating upper and lower case identically, but case-sensitive
searching, you only need to override the FindString, FindStringExact,
and SelectString operations. Note that you have to actually get the
text and compare it yourself; you cannot call the superclass
FindString, etc. functions. For an example of subclassing a listbox,
see my Horizontal Scrolling ListBox on my MVP Tips site (free
download). This shows overriding functions, but in this case it still
calls the superclass functions to do the work. You'll need to do a
loop
int CMyListBox::FindStringExact(int start, LPCTSTR string)
{
for(int i = start+1; i < CListBox::GetCount(); i++)
{
CString s;
CListBox::GetText(i, s);
if(tcscmp(s, string) == 0)
return i;
}
return LB_ERR;
}

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

Igor Lychakov

unread,
Mar 13, 2001, 6:10:26 PM3/13/01
to

Joseph,
I have implemented owner-draw combobox, and DrawItem function.
The problem is that after selection "aaa" and opening again
dropdown listbox of the combobox the "aaa" item is not selected,
no items are selected. I would expect that "aaa" is selected.
A don't think that solution is in CompareItem(), since this function is
not called if I disable <sort> attribute in the box.
I tried to call SetTopIndex(), SetScrollPos() and
SetCurSel() from ::OnLButtonDown() and ::OnDropdown() functions,
but the effect is zero.
Thanks,
Igor

Joseph M. Newcomer

unread,
Mar 14, 2001, 8:58:39 PM3/14/01
to
Selection is different. You actually have to draw the selection colors
yourself; once you do "owner-draw" it is all up to you! You might want
to check out my Logging ListBox package on my MVP Tips site to see how
this is done. You'll need to make a few changes to handle the
combo-box flags, which might be different from the non-combo-box flags
(I've got a few owner-draw combo boxes floating around on my site as
well, but I forget which programs use them). You will do things like
if(selected)
{
bkcolor = ::GetSysColor(COLOR_HIGHLIGHT);
fgcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
}
else
{
bkcolor = ::GetSysColor(COLOR_WINDOW);
fgcolor = ::GetSysColor(COLOR_WINDOWTEXT);
}

If you don't have code resembling the above (I forget what bit is
tested for the "selected", but see my code, which does it right), you
are not going to see any selection boxes. And you have to draw the
actuall background color before laying down any text (and I recommend
dc.SetBkMode(TRANSPARENT) for best effect). You also have to call
DrawFocusRect to get the rectangle to display.
joe

On Tue, 13 Mar 2001 15:10:26 -0800, Igor Lychakov <ilyc...@ynn.com>
wrote:

0 new messages