简体   繁体   English

如何比较组合框中的所选项目以匹配属性中的设置类

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

My combobox contains 'Control', 'Alt' & 'Shift'. 我的组合框包含“控件”,“ Alt”和“ Shift”。 My predefined string in the settings class is 'Control'. 我在设置类中的预定义字符串是“控件”。

How do i compare those 2 Strings : 我如何比较这两个字符串:

  1. = SelectedItem in the Combobox =组合框中的SelectedItem
  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. 因为我想将更改后的selectedItem保存在我的设置类中,所以每当我再次启动该应用程序时,都应该在组合框中加载新的SelectedItem。

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. SelectedItem属性返回用于填充组合框的完整listitem对象。 If you are looking for the value, you can use SelectedValue.ToString() 如果要查找值,则可以使用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();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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