Winforms 列表框所选项目winform

Winforms 列表框所选项目winform,winforms,Winforms,Listbox.SelectedItem=value对我不起作用。实际上,我想以编程方式更改选择。我没有要选择的列表框的索引,只有文本。实际上,displaymember是由组合框提供的。当组合框中的选择更改时,结果更改也将反映在列表框中 void PopulateList() { this.list.DataSource = (IList)ClassDsnManager.GetDataSourceNames(); this.list.Disp

Listbox.SelectedItem=value对我不起作用。实际上,我想以编程方式更改选择。我没有要选择的列表框的索引,只有文本。实际上,displaymember是由组合框提供的。当组合框中的选择更改时,结果更改也将反映在列表框中

      void PopulateList()
    {
        this.list.DataSource = (IList)ClassDsnManager.GetDataSourceNames();
        this.list.DisplayMember = "Name";
        this.list.ValueMember = "Driver";

    }
 void ComboSelectedIndexChanged(object sender, EventArgs e)
      {
        if (Combo.SelectedIndex != -1)
        {
            ClassDatabase selecteditem = (ClassDatabase)Combo.SelectedItem;

            source.Text = selecteditem.source;

            string destination= selecteditem.SqlConn;
            if (!string.IsNullOrEmpty(destination))
            {
                string[] connectionValue = connection.Split(Convert.ToChar(";"));
                string dsnName = connectionValue[0].Substring(4, connectionValue[0].Length - 4);
                // this is the list box whose value i want to set
                lbDSN.SelectedItem = dsnName;

            }

        }

    }

解决方案1:
组合框的
SelectedIndexChanged
中,只需编写

listBox1.SelectedItem = comboBox1.SelectedItem.ToString();

解决方案2:
组合框的
下拉样式更改为
简单
。它将显示
组合框
,就像一个
列表框

如果您显示用于填充列表的代码,会有所帮助box@JohnArlen你能看一下吗?我已经贴好密码了