C#或wpf或MFC ComboBox.OnSelectionChanged(SelectionChangedEventArgs) 获取变改后的值,不要直接获取。又一坑

WPF版  C#

using FT_Tools;
using MSFramework.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfM20UpdateFW;

namespace WpfDownloadTool
{
    /// <summary>
    /// SettingsWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SettingsWindow : Window
    {
        List<BindingSettingsClass> bindingSettingsList = new List<BindingSettingsClass>();

        public SettingsWindow()
        {
            InitializeComponent();
            Dictionary<string, string> config = IniFile.ReadAll();
            foreach (KeyValuePair<string, string> k in config)
            {
                bindingSettingsList.Add(new BindingSettingsClass() { Name = k.Key, Value = k.Value, Describe = "TEST" });
            }
            myListBox.ItemsSource = bindingSettingsList;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try {
                for (int i = 0; i < myListBox.Items.Count; i++)//特殊的处理一下
                {
                    BindingSettingsClass o = (BindingSettingsClass)(myListBox.Items.GetItemAt(i));
                    if (o.Name.Equals("SP"))
                    {
                        ComboBox sp = (ComboBox)MyAPI.getControl(myListBox, i, "ComboBoxSelect");
                        sp.Items.Add("0_Close");
                        sp.Items.Add("1_1902");
                        sp.Items.Add("2_1902T");
                        sp.Items.Add("3_Max332555");
                        sp.SelectionChanged += Sp_SelectionChanged;
                        sp.SelectedIndex = int.Parse(o.Value);
                        sp.Visibility = Visibility.Visible;
                    }
                    else if (o.Name.Equals("AP"))
                    {
                        ComboBox ap = (ComboBox)MyAPI.getControl(myListBox, i, "ComboBoxSelect");
                        ap.Items.Add("0_Close");
                        ap.Items.Add("1_F200");
                        ap.Items.Add("2_F600");
                        ap.Items.Add("3_F100");
                        ap.Items.Add("4_F210 F200-A");
                        ap.SelectionChanged += Ap_SelectionChanged;
                        ap.SelectedIndex = int.Parse(o.Value);
                        ap.Visibility = Visibility.Visible;
                    }
                    else if (o.Name.Equals("AP_File"))
                    {
                        Button buttonSP = (Button)MyAPI.getControl(myListBox, i, "ButtonSelect");
                        buttonSP.Visibility = Visibility.Visible;
                        buttonSP.Click += Button_Click_ap;
                    }
                    else if (o.Name.Equals("SP_SigFile"))
                    {
                        Button buttonSP = (Button)MyAPI.getControl(myListBox, i, "ButtonSelect");
                        buttonSP.Visibility = Visibility.Visible;
                        buttonSP.Click += Button_Click_sp_sig;
                    }
                    else if (o.Name.Equals("SP_RSAKeyFile"))
                    {
                        Button buttonSP = (Button)MyAPI.getControl(myListBox, i, "ButtonSelect");
                        buttonSP.Visibility = Visibility.Visible;
                        buttonSP.Click += Button_Click_sp_rsa;
                    }
                    else
                    {
                        TextBlock tb = (TextBlock)MyAPI.getControl(myListBox, i, "textBlockDescribe");
                        tb.Visibility = Visibility.Visible;
                    }
                }
            } catch (Exception e2) { MessageBox.Show(e2.StackTrace); }
          
        }
        private void Sp_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox c = (ComboBox)sender;
            int index=c.SelectedIndex;
            string cText=c.Items.GetItemAt(c.SelectedIndex).ToString();
            for (int i = 0; i < myListBox.Items.Count; i++)//特殊的处理一下
            {
                BindingSettingsClass o = (BindingSettingsClass)(myListBox.Items.GetItemAt(i));
                if (o.Name.Equals("SP"))
                {                   
                    o.Value = cText.Substring(0,1);
                    return;
                }
            }
        }
        private void Ap_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox c = (ComboBox)sender;
            int index = c.SelectedIndex;
            string cText = c.Items.GetItemAt(c.SelectedIndex).ToString();
            for (int i = 0; i < myListBox.Items.Count; i++)//特殊的处理一下
            {
                BindingSettingsClass o = (BindingSettingsClass)(myListBox.Items.GetItemAt(i));
                if (o.Name.Equals("AP"))
                {
                    if (cText.Equals("")) { return; }
                    o.Value = cText.Substring(0, 1);
                    return;
                }
            }
        }

        private void Button_Click_ap(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new Microsoft.Win32.OpenFileDialog()
            {
                Filter = "F200 F600 AP|*.mbn|F100 AP|*.txt|F200-A F210 AP|*.pac",
                Multiselect = false
            };
            if (openFileDialog.ShowDialog() == true)
            {
                Log("AP_File=" + openFileDialog.FileName);
                IniFile.WritePrivateProfileString(DownloadSP1902QualComm.configAppName, DownloadSP1902QualComm.APPath, DownloadSP1902QualComm.AP_File = openFileDialog.FileName, IniFile.m_FileName);
            }
        }

        private void Button_Click_sp_sig(object sender, RoutedEventArgs e)
        {
            if (DownloadSP1902QualComm.SP == 3)
            {
                //文件夹
                var dialog = new System.Windows.Forms.FolderBrowserDialog()
                {
                    Description = "Please select SP File path"
                };

                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Log("SP_SigFile=" + dialog.SelectedPath);
                    IniFile.WritePrivateProfileString(DownloadSP1902QualComm.configAppName, DownloadSP1902QualComm.SigFilePath, DownloadSP1902QualComm.SP_SigFile = dialog.SelectedPath, IniFile.m_FileName);
                }
            }
            else
            {
                var openFileDialog = new Microsoft.Win32.OpenFileDialog()
                {
                    Filter = "SP File|*.SIG|F100 SP|*.hex",
                    Multiselect = false
                };
                if (openFileDialog.ShowDialog() == true)
                {
                    Log("SP_SigFile=" + openFileDialog.FileName);
                    IniFile.WritePrivateProfileString(DownloadSP1902QualComm.configAppName, DownloadSP1902QualComm.SigFilePath, DownloadSP1902QualComm.SP_SigFile = openFileDialog.FileName, IniFile.m_FileName);
                }
            }    
        }
        private void Button_Click_sp_rsa(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new Microsoft.Win32.OpenFileDialog()
            {
                Filter = "SP File|*.RSA",
                Multiselect = false
            };
            if (openFileDialog.ShowDialog() == true)
            {
                Log("SP_RSAKeyFile=" + openFileDialog.FileName);
                IniFile.WritePrivateProfileString(DownloadSP1902QualComm.configAppName, DownloadSP1902QualComm.RSAKeyPath, DownloadSP1902QualComm.SP_RSAKeyFile = openFileDialog.FileName, IniFile.m_FileName);
            }
        }
        private void Log(string s)
        { }

       
    }
}

MFC

void CScanLicenceInfoUploadDlg::OnSelchangeComboDevices()
{
	int index = ((CComboBox*)GetDlgItem(IDC_COMBO_DEVICES))->GetCurSel();
	((CComboBox*)GetDlgItem(IDC_COMBO_DEVICES))->SetCurSel(index);
	FilterList();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黄人软件

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值