2012-05-02 3 views
0

기본 폼에 콤보 상자, 텍스트 상자 및 단추가 있습니다. 콤보 상자에는 변경할 수없는 항목이 있지만 선택한 항목에 새 값을 입력하여 항목 자체를 변경할 수 있습니다. 그림의 예에서 대소 문자를 변경하더라도 ComboBox 항목이 업데이트되지 않습니다.

enter image description here

예상 같은 "식별자"선택 항목 "ID"에서 콤보 박스의 변화에 ​​"식별자"로 I 입력 문자열을 경우. 그러나 "id"를 입력하면 논리 (아래)가 정상적으로 실행되고 항목은 업데이트되지만 시각적으로 항목은 "ID"에서 "id"로 변경되지 않습니다. 다음 코드 샘플이 작동하기 때문에 여기에

, 나는 ComboBox의 일부 문자열 비교를하고 있다고 생각 버튼

private void btnApply_Click(object sender, EventArgs e) { 

    string newValue = txtNewName.Text; 

    if(string.IsNullOrWhiteSpace(newValue)) { 
     MessageBox.Show("Please input a new column name"); 
     return; 
    } 

    if(cmbHeaderNames.Items.Contains(newValue)) { 
     MessageBox.Show("A column with that name already exists"); 
     return; 
    } 

    cmbHeaderNames.Items[cmbHeaderNames.SelectedIndex] = newValue; 

    txtNewName.Text = ""; 

} 
+1

이 작업을 수행하려면 [BindingList ] (http://msdn.microsoft.com/en-us/library/ms132679.aspx)을 데이터 소스로 사용하려고합니다. – Candide

답변

3

의 이벤트 처리기에 대한 코드입니다.

if (comboBox1.SelectedItem.ToString().ToUpper() == textBox1.Text.ToUpper()) 
{ 
    comboBox1.Items[comboBox1.SelectedIndex] = string.Empty; 
    comboBox1.Items[comboBox1.SelectedIndex] = textBox1.Text; 
} 

분명히 업데이트가의 ToUpper() 또는 ToLower는() 적용 할 때 두 개의 문자열 값이 동일하지 않은 경우에 적용됩니다.

+0

이것은 내 사용에 충분하다. 감사. – daniel

관련 문제