2012-03-13 4 views
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; 

      } 

     } 

    } 
+1

목록 상자를 채우는 데 사용하는 코드를 보여 주면 도움이 될 것입니다. –

+0

@ JohnArlen 코드를 붙여 넣으셨습니까? – arjun

답변

2

Solution1 : ComboboxSelectedIndexChanged에서 단순히

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

Solution2 쓰기 : SimpleComboboxDropDownStyle을 변경. 과 같은 Combobox이 표시됩니다.