WinForms ComboBox SelectedIndexChanged event and SelectedValue assignment.

I am using WinForms.ComboBox and wanted to handle SelectedIndexChanged events. I found that when DataSource is assigned adding each row caused SelectedIndexChanged.
It is a known and aknowledged by Microsoft problem and there are possible workarounds(e.g see http://www.bobpowell.net/ComboBinding.htm  or http://www.windowsitpro.com/Article/ArticleID/41825/41825.html ).

I desided that I don't need to set DataSource but will use

lst.Items.Clear();
lst.Items.AddRange(coln.ToArray());

It helped with SelectedIndexChanged event not firing before user actually change the value.

The new problem was that  when  I programmatically set cmb.SelectedValue=value , selection of the combobox was not changed and SelectedIndex was still -1.

Checking System.Windows.Forms.ListControl.set_SelectedValue in Reflecter confirmed, that only for bounded controls ( dataManager != null) selection would be changed by assigning SelectedValue.

It seems that the best approach would be to temprary remove comboBox_SelectedIndexChanged event handler before data binding, assign DataSource,DisplayMember, ValueMember , assign SelectedValue and then add comboBox_SelectedIndexChanged event handler again.

Storing User Configurations in .Net 1.1

 .Net 2.0 will introduce My.Settings to store user preferences. For .Net 1.1 i wanted to use approach described by Rockford Lhotka in MSDN article “Storing User Configurations”. It requires to create derived class with properties that you want to store.

I found 2 tips when created the derived class that is using IsolatedStorage.

1. Ignore FileNotFoundException error when load storage the first time.
2. Use assignment with cast when Load class from storage, e.g.
 
 MySettings=MySettings.Load();

See the sample derived class below:

      public class MySettings: vbUserSettings.UserSettingsBase

      {//based on http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet07082003.asp

            //in .Net 2.0 will be replaced with My.Settings  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/vbmysettings.asp 

            //Constructors

            public MySettings(): base()//required for serialization

            {}

            public MySettings(vbUserSettings.UserStorageOption StorageOption): base(StorageOption)

            {}

           

            /// <summary>

            /// Loads casted object

            /// </summary>

            /// <returns></returns>

            /// <remarks> IMPORTANT: return value of the function should be used</remarks>

            /// <example>

            ///         MySettings=MySettings.Load();

            ///     MySettings.Load();// Incorrect!!, the cast is not applied and derived class properties are not assigned

            /// </example>

            public  MySettings Load()

            {

                  try

                  {

                        return (MySettings)Restore();

                  }

                  catch (vbUserSettings.UserSettingsException  exc) //System.IO.FileNotFoundException

                  {

                        Debug.WriteLine(exc.ToString());

                        //new file, ignore the error

                  }

                  return this;     

            }

            //Derived class properties and fields

            public ImportModeEnum importMode;

      }

 

«October»
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345