6

私の友人、私は自分のウィンドウフォームにコンボボックスを持っています。データベースからのデータを入力できますが、ユーザーがコンボボックスの横に文字を入力すると、コンボボックスに入力できません。 " コンボボックスとコンボボックスの横にドロップダウンする必要があり、文字 "R" ですべての可能なものを示します

4

3 に答える 3

5
  1. に設定yourComboBox.AutoCompleteSourceAutoCompleteSource.ListItems;ます(yourComboBox.Itemsデータベースからすでに入力されている場合)
  2. yourComboBox.AutoCompleteModeに設定SuggestAppend
于 2013-03-05T08:45:34.173 に答える
1

これがあなたに役立つことを願っています:

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;
}

ここから

于 2013-03-05T08:47:02.790 に答える
1

コンボボックスの KeyUp イベントと連携し、comboBox.Text を使用して、comboBox.Items コレクションをフィルタリングして、入力された文字を含むものだけを表示する必要があります。また、comboBox ウィンドウも強制的にドロップダウンにする必要があります。

于 2013-03-05T08:44:50.420 に答える