Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm quite confused about the way ComboBox's FindString() method works.

 

Consider the following example:

ComboBox myComboBox = new ComboBox();

myComboBox.Items.AddRange(new string[] { "Test1", "Test2", "Test3", "" });

MessageBox.Show(myComboBox.FindString("Test1").ToString());
MessageBox.Show(myComboBox.FindString("Test2").ToString());
MessageBox.Show(myComboBox.FindString("Test3").ToString());
MessageBox.Show(myComboBox.FindString("").ToString());

 

The first three output as you would expect 0, 1, 2 but the last one output's 0. ***? Who wrote this method anyway. I mean I could understand it returning -1 or something like that but it is returning 0 which is "Test 1" which is not null, and not an empty string "".

  • Administrators
Posted
An empty string is pretty much an edge case scenario as it returns the index of an item that begins with the specified text, and the items are checked in order (or so it appears). Trying to match against an empty string appears to match any entry - then again how often would you expect to find empty strings in a combobox under normal usage?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...