我想使用combobox对列表框进行排序, 组合框将包括A-Z和Z-A,那么我该怎么做才能让它工作?
我的一些列表框代码,lst_OrderName
是我想要排序的代码。
private void AllorderBySearch()
{
using (connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("select* from Tbl_order WHERE CustomerNo = '" + txt_CustomerNo.Text + "' And OrderName LIKE '%" + txt_OrderNo.Text + "%' AND OrderName LIKE '%" + txt_OrderNo.Text + "%' AND OrderName LIKE '%" + txt_OrderNo.Text + "%' AND Date between '" + dateTimePicker1.Text + " 00:00:00.000' AND '" + dateTimePicker1.Text + " 23:59:59.999'; ", connection))
{
DataTable Tbl_order = new DataTable();
connection.Open(); //opens the connection
adapter.Fill(Tbl_order);
connection.Close(); //Closes the connection
lst_CustomerNo.DataSource = Tbl_order; //assigns a datasource
lst_CustomerNo.DisplayMember = "CustomerNo"; //assigns display
lst_CustomerNo.ValueMember = "CustomerNo";
lst_OrderName.DataSource = Tbl_order;
lst_OrderName.DisplayMember = "OrderName";
lst_OrderName.ValueMember = "OrderName";
lst_Quantity.DataSource = Tbl_order;
lst_Quantity.DisplayMember = "Quantity";
lst_Quantity.ValueMember = "Quantity";
lst_Price.DataSource = Tbl_order;
lst_Price.DisplayMember = "Price";
lst_Price.ValueMember = "Price";
lst_datetime.DataSource = Tbl_order;
lst_datetime.DisplayMember = "Date";
lst_datetime.ValueMember = "Date";
}
}
我创建了组合框,但我没有做任何事情,但是我不知道如何按照我想要的方式制作它。你能帮帮我吗?
答案 0 :(得分:0)
您必须使用临时对象进行排序,如冒泡排序
答案 1 :(得分:0)
当您使用DataTable作为数据源时,以下内容应该有效:
{{1}}
将上述事件附加到您的组合框SelectedIndexChanged操作..