wxListBox::SetStringSelection behaviour
Francesco Montorsi
f18m_cpp217828 at yahoo.it
Mon Jul 3 04:55:42 PDT 2006
Vadim Zeitlin ha scritto:
> On Sun, 2 Jul 2006 15:29:33 +0000 (UTC) Francesco Montorsi <f18m_cpp217828 at yahoo.it> wrote:
>
> FM> I've found that using
> FM> wxListBox::SetStringSelection(wxT("string-not-in-the-listbox")); always causes
> FM> an assert.
> FM> Since SetStringSelection returns a bool indicating the success/failure of the
> FM> operation, I think that the following patch should be applied:
>
> This has been asked for in the past so I must be missing something but,
> in spite of realizing this, I still don't understand why would you ever
> want to call SetStringSelection() with a string not present in the control.
because in case you want to select a string e.g. coming from user input,
you need to do:
int n = listbox->FindString(str);
if (n!= wxNOT_FOUND)
listbox->SetSelection(n);
and since SetStringSelection() returns a bool and the assert - which
happens in case the string is missing - is not documented, I expected
SetStringSelection() to just be a shorthand for the code above...
> And as nobody checks the return code of SetStringSelection() anyhow,
well, I did :)
> I'm
> pretty sure that any bug accidentally resulting in this call would be much
> harder to find without the assert.
I don't think as the documentation currently clearly says:
"Return value = true if the specified string has been selected, false if
it wasn't found in the control."
Francesco
More information about the wx-dev
mailing list