简体   繁体   中英

How do I compare the selected item in a combobox to match my settings class in the properties

My combobox contains 'Control', 'Alt' & 'Shift'. My predefined string in the settings class is 'Control'.

How do i compare those 2 Strings :

  1. = SelectedItem in the Combobox
  2. = predefined string in the settings class

Because i want to save the changed selectedItem in my settings class, so whenever i start the application again it should load the new SelectedItem in the Combobox.

Edit: Code looking actually like this, but it wont work.

if (cmbModifier.SelectedItem.ToString() != ClipboardPro.Properties.Settings.Default.SavedModifier.ToString())
{
      modkey = cmbModifier.SelectedItem.ToString();

      ClipboardPro.Properties.Settings.Default.SavedModifier = modkey;
      ClipboardPro.Properties.Settings.Default.Save();

}

the SelectedItem property returns the full listitem object you used to fill your combobox. If you are looking for the value, you can use SelectedValue.ToString()

if (cmbModifier.SelectedValue.ToString() != ClipboardPro.Properties.Settings.Default.SavedModifier.ToString())
{
      modkey = cmbModifier.SelectedValue.ToString();

      ClipboardPro.Properties.Settings.Default.SavedModifier = modkey;
      ClipboardPro.Properties.Settings.Default.Save();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM