SetStringSelection case insensitive!?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 299
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

SetStringSelection case insensitive!?

Post by rocrail »

Hi,

in the wx2.8 API is it not documented but in the wx3.0:
bool wxItemContainerImmutable::SetStringSelection ( const wxString & string )
Selects the item with the specified string in the control.

This method doesn't cause any command events to be emitted.

Notice that this method is case-insensitive, i.e. the string is compared with all the elements of the control case-insensitively and the first matching entry is selected, even if it doesn't have exactly the same case as this string and there is an exact match afterwards.

Parameters
string The string to select.
Returns
true if the specified string has been selected, false if it wasn't found in the control.
Why is this behaviour so implemented. Looking in the source this is only true in case the ComboBox is not sorted....
No I have to replace all SetStringSelection calls with SetValue, but this is not possible with wxChoices...
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: SetStringSelection case insensitive!?

Post by doublemax »

I don't know why it was implemented that way, either because it makes sense in most cases or because one or more native implementations work that way.

In any case, the combination of FindString() with bCase = true, followed by SetSelection() should work.
Use the source, Luke!
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 299
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: SetStringSelection case insensitive!?

Post by rocrail »

Thanks for your answer.

As far as I can see is this bCase flag not able to set by the wxWidgets API.
Internally this flag is set when the control is sorted automatically, which is in my case not possible.

IMHO compare strings should be always case sensitive...
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: SetStringSelection case insensitive!?

Post by doublemax »

As far as I can see is this bCase flag not able to set by the wxWidgets API.
Yes, you can't change the behavior of SetStringSelection(), but you can call FindString() yourself with caseSensitive/bCase = true and then call SetSelection() and select the item by index.

http://docs.wxwidgets.org/trunk/classwx ... 5a73e669bb
Use the source, Luke!
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 299
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: SetStringSelection case insensitive!?

Post by rocrail »

Hi,

this Work-Around is OK in case you have only a few Combos and or choices, but in case of many dialogs with many combos this is not the way to go.
The Combos I could solve with using SetValue instead of SetStringSelection, but with Choices and Listboxes this is not possible.
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: SetStringSelection case insensitive!?

Post by doublemax »

That could be solved with a macro or a small inline function.

But do you really need a case-sentitive behavior in all cases?

In any case, if you want the wxWidgets behavior to change, this is the wrong place to ask, you'd have to ask in the wx-users group:
https://groups.google.com/forum/#!forum/wx-users

But it's unlikely that the default behavior will be changed, as this could silently break existing code. Maybe a "caseSensitive" parameter could be added to SetStringSelection(). If you could confirm that it's possible to implement that on all platforms and if you could even provide a patch, then there is a good chance, it could find its way into wxWidgets.
Use the source, Luke!
Post Reply