Well, I'm not sure it's exactly full proof, but it will keep you from making a stupid mistake in your application's functionality.

There are several ways to select a list item when you are loading a page or a form. The most common method is to just set the SelectedItem property to be the text that you would like to see defaulted into the dropdown or listbox, like so:

cboServerSchedule.SelectedItem = sMyString;

This works find and dandy as long as the value that you are assigning to SelectedItem exactly matches your variable or value. And when I say exactly, I mean just that: exactly.

I ran into a situation this week where it was possible for the user to edit, outside of the application, the value that I would be using to set SelectedItem of my DropDown. This would cause the application to basically set the default value for the DropDown. Since I had no control over what the user could do, and the setting the application was writing to the registry was case-sensitive, it presented me with a problem.

That was when I remembered that a very, very, long time ago, I had already solved this problem with just a couple of extra lines of code:

iFindStr = cboClientSchedule.FindString(sMyString);

if (iFindStr != -1)
   cboClientSchedule.SelectedIndex = iFindStr;

Using the FindString function for the DropDown, you are able to perform a case-insensitive search for a selected value. If the value is found within the Items collection, FindString returns that index; otherwise, it returns a -1.

I simply check the return value and if it's not -1, I assign the SelectedIndex ( instead of SelectedItem ) to that value. The final key to this solution was to set the items collection of my DropDown to be valid values for the application that would later be reading the value from the Registry.