Search code examples
c++visual-c++wxwidgets

wxChoice::SetString() Index Error


I've finally gotten around to messing with the wxChoice control in my application, and for some reason whenever I attempt to modify the text of a column, I get the error:

....\src\msw\choice.cpp(348): assert "IsValid(n)" failed in wxChoice::SetString(): invalid item index in wxChoice::SetString

The error itself makes it quite obvious that the item index isn't valid, but based off of my code and the (not very descriptive) documentation, I should only need to set the number of columns, then I'd be allowed to edit the text at a given index.

Here's a snippet from my project:

int phones = Phones->size();
choiceDevice->SetColumns(phones); // Value greater than 0
choiceDevice->SetString(phones - 1, pInstance->ProfileName); // Should assign the last index the value of the ProfileName.

Solution

  • As Alex had said, I shouldn't be using wxChoice::SetColumns on Windows since it has no affect. I found that I have to use wxChoice::Append instead of setting the number of columns, then setting the individual string.