0

次のようなコンボボックス機能が必要です-

項目のリストが非常に大きいため、コンボ ボックスには項目が表示され、オートコンプリート機能があります。

オートコンプリート機能を使用してボックスに入力することで、ユーザーが項目リストから値を選択できるようにしたいと考えています。ユーザーがリストにないものを入力すると、使用可能な値が自動的に選択されます。

間違ったテキストをデータベースに送信したくありません。

このコンボ ボックスは編集可能で、オート コンプリートですが、編集可能な値を受け入れません。ユーザーは ... と入力してリストから選択する必要があります。

private void FrmGroupCreation_Load(object sender, EventArgs e)
    {
        string con = ConfigurationManager.ConnectionStrings["SaiCon"].ConnectionString;
        using (SqlConnection connect=new SqlConnection(con))
        {
            //data table for combox type of account 
            SqlDataAdapter da = new SqlDataAdapter("SELECT *FROM dbo.Type_of_Account",connect);

            DataTable dt=new DataTable();
            da.Fill(dt);
            for (int i = 0; i < dt.Rows.Count ; i++)
            {
                cbTypeofAccount.Items.Add(dt.Rows[i]["type_Of_Acct"]);
            }
            //data table for combobox principle account type
            SqlDataAdapter da1 = new SqlDataAdapter("SELECT *FROM dbo.Principle_Account", connect);

            DataTable dt1 = new DataTable();
            da1.Fill(dt1);
            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                cbPrinciple_account_type.Items.Add(dt1.Rows[i]["Principle_Account"]);
            }
            //data table for combobox Under the group
            SqlDataAdapter da2 = new SqlDataAdapter("SELECT *FROM dbo.Head_group_Account", connect);

            DataTable dt2 = new DataTable();
            da2.Fill(dt2);
            for (int i = 0; i < dt2.Rows.Count; i++)
            {
                cbUnder_the_group.Items.Add(dt2.Rows[i]["Account_name"]);
            }
        }

    }
4

1 に答える 1

1

次のことを行う必要があります。

1-コンボボックスを埋めるためにforループを実行する代わりに、コンボボックスのデータソースをデータテーブルと等しく設定し、値メンバーと表示メンバーを設定します

 cbTypeofAccount.DataSource = dt;
 cbTypeofAccount.DisplayMember = "type_Of_Acct";
 cbTypeofAccount.ValueMember = "your table id";

2-コンボボックスのドロップダウンスタイルを変更して編集可能にします

 cbTypeofAccount.DropDownStyle = ComboBoxStyle.DropDown;
于 2013-03-29T16:35:59.450 に答える