簡體   English   中英

如何使用C#WinForms在組合框中選擇多個項目

[英]How to Selecting a More than one items in Combobox using C# WinForms

在這里,我添加了一個代碼,用於使用數據庫向Combobox中添加項目,但是我不知道如何在Combobox中使用多個選擇項。

        admin = "Admin";
        string query = "Select FirstName from Register where UserType =  '" + admin + "'  ";
        SqlDataAdapter da = new SqlDataAdapter(query, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        comboBox1.Text = "--- Select an Admin Here ---";
        foreach (DataRow dr1 in ds.Tables[0].Rows)
        {
            comboBox1.Items.Add(dr1["FirstName"].ToString());
        }

使用此代碼:

ListBox listBox1 = new ListBox();
// Set the SelectionMode to select multiple items.
listBox1.SelectionMode = SelectionMode.MultiExtended;

// Select three initial items from the list.
listBox1.SetSelected(0, True);
listBox1.SetSelected(2, True);
listBox1.SetSelected(4, True);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM