0
Listbox.SelectedItem = valueが機能しません。実際には、プログラムで選択範囲を変更したいと思います。リストボックスのインデックスを選択するのではなく、テキストのみを選択します。実際、displaymemberはコンボボックスで提供されています。コンボボックスで選択が変更されると、結果として得られる変更もリストボックスに反映されます。リストボックス選択項目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;
}
}
}
リストボックスを作成するために使用するコードを表示した場合は助かります –
@JohnArlenコードを貼り付けてください – arjun