headkaze Posted October 6, 2006 Posted October 6, 2006 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 "". Quote
Administrators PlausiblyDamp Posted October 6, 2006 Administrators Posted October 6, 2006 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.