how to save ComboBoxitem in ComboBox (Visual studio wpf c#)

  Uncategorised

i tring to save some data in Properties like (String) but it doesn’t save and it doesn’t load!
why?

if i am using this way in ( visual studio win forms it work ) i used this code before start using WPF

im using visual studio windows-plat-form and Thank you
I hope someone can answer my question quickly yyyyyyyy


private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            #region
            if (Properties.Settings.Default.ShortCuts1 == "None") //-------> this is "string 1"
            {
                //ComboBox1.SelectedIndex = 0;
                F1bool = false;
                F2bool = false;
                F3bool = false;
            }
            if (Properties.Settings.Default.ShortCuts1 == "F1")
            {
                //ComboBox1.SelectedIndex = 1;
                F1bool = true;
                F2bool = false;
                F3bool = false;
            }
            if (Properties.Settings.Default.ShortCuts1 == "F2")
            {
                ComboBox1.SelectedIndex = 2;
                F1bool = false;
                F2bool = true;
                F3bool = false;
            }
            if (Properties.Settings.Default.ShortCuts1 == "F3")
            {
                //ComboBox1.SelectedIndex = 3;
                F1bool = false;
                F2bool = false;
                F3bool = true;
            }

            // ComboBox 2

            if (Properties.Settings.Default.ShortCuts2 == "None")
            {
                //ComboBox2.SelectedIndex = 0;
                RCtrlbool = false;
                RShiftbool = false;
                F7bool = false;
            }
            if (Properties.Settings.Default.ShortCuts2 == "RCtrl")
            {
                //ComboBox2.SelectedIndex = 1;
                RCtrlbool = true;
                RShiftbool = false;
                F7bool = false;
            }
            if (Properties.Settings.Default.ShortCuts2 == "RShift")
            {
                //ComboBox2.SelectedIndex = 2;
                RCtrlbool = false;
                RShiftbool = true;
                F7bool = false;
            }
            if (Properties.Settings.Default.ShortCuts2 == "F7")
            {
                //ComboBox2.SelectedIndex = 3;
                RCtrlbool = false;
                RShiftbool = false;
                F7bool = true;
            }
            #endregion

            ComboBox1.SelectedItem = Properties.Settings.Default.ShortCuts1;
            ComboBox2.SelectedItem = Properties.Settings.Default.ShortCuts2;
        }

private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBox1.SelectedItem.ToString() == "None")
            {
                F1bool = false;
                F2bool = false;
                F3bool = false;
            }
            if (ComboBox1.SelectedItem.ToString() == "F1")
            {
                F1bool = true;
                F2bool = false;
                F3bool = false;
            }
            if (ComboBox1.SelectedItem.ToString() == "F2")
            {
                F1bool = false;
                F2bool = true;
                F3bool = false;
            }
            if (ComboBox1.SelectedItem.ToString() == "F3")
            {
                F1bool = false;
                F2bool = false;
                F3bool = true;
            }
            Properties.Settings.Default.ShortCuts1 = ComboBox1.SelectedItem.ToString();
            Properties.Settings.Default.Save();
            // End ALL
        }

        private void ComboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBox2.SelectedItem.ToString() == "Test")
            {
                RCtrlbool = false;
                RShiftbool = false;
                F7bool = false;
            }
            if (ComboBox2.SelectedItem.ToString() == "RCtrl")
            {
                RCtrlbool = true;
                RShiftbool = false;
                F7bool = false;
            }
            if (ComboBox2.SelectedItem.ToString() == "RShift")
            {
                RCtrlbool = false;
                RShiftbool = true;
                F7bool = false;
            }
            if (ComboBox2.SelectedItem.ToString() == "F7")
            {
                RCtrlbool = false;
                RShiftbool = false;
                F7bool = true;
            }
            Properties.Settings.Default.ShortCuts2 = ComboBox2.SelectedItem.ToString();
            Properties.Settings.Default.Save();
            // End ALL
        }

Source: Visual Studio Questions

LEAVE A COMMENT