0
Listbox.SelectedItem = value對我不起作用。其實我想以編程方式改變選擇。我沒有要選擇的列表框的索引,但只有文本。實際上,顯示器部件由組合框提供。當組合框中的選擇更改時,生成的更改也將反映在列表框中。listbox selected item winform
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;
}
}
}
它會幫助,如果你顯示你用來填充列表框的代碼 – 2012-03-13 06:24:46
@JohnArlen你能否看到它我已經粘貼了代碼 – arjun 2012-03-13 06:55:35