2013-03-05 7 views
4

내 친구, 내 Windows 양식에 콤보 상자가 있습니다. 데이터베이스의 데이터로 채울 수 있습니다. 하지만 필자는 콤보 상자 옆에 콤보 상자의 사용자 입력 문자가있는 경우 콤보 상자와 콤보 상자의 아래쪽에 "R"문자를 입력하면 문자 "R"이있는 모든 가능성이 표시됩니다.콤보 상자를 작성하는 동안 콤보 상자를 자동으로 채우는 방법 C#

+0

R efer ** [this] (http://stackoverflow.com/questions/805638/making-a-combo-box-editable) ** 하나 – andy

답변

5
  1. 설정 yourComboBox.AutoCompleteSourceAutoCompleteSource.ListItems;에 (경우 yourComboBox.Items 이미 데이터베이스에서 채워졌다)
  2. 이는 데 도움이 SuggestAppend
+0

감사합니다 친구 그것은 나에게 많은 도움이된다. – Roshan

1

comboBox의 KeyUp 이벤트로 묶어야하며 comboBox.Text를 사용하여 comboBox.Items 컬렉션을 필터링하여 입력 된 문자 만 표시하도록합니다. 또한 콤보 상자 창을 강제로 드롭 다운해야합니다.

1

희망에 yourComboBox.AutoCompleteMode 설정 :

private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    char ch = e.KeyChar; 
    string strToFind; 

    // if first char 
    if (lastChar == 0) 
     strToFind = ch.ToString(); 
    else 
     strToFind = lastChar.ToString() + ch; 

    // set first char 
    lastChar = ch; 

    // find first item that exactly like strToFind 
    int idx = comboBox1.FindStringExact(strToFind); 

    // if not found, find first item that start with strToFind 
    if (idx == -1) idx = comboBox1.FindString(strToFind); 

    if (idx == -1) return; 

    comboBox1.SelectedIndex = idx; 

    e.Handled = true; 
} 

void comboBox1_GotFocus(object sender, EventArgs e) 
{ 
    // remove last char before select new item 
    lastChar = (char) 0; 
} 

here

에서을
관련 문제