我正在尝试学习C#并且我正在构建这个库存系统,但是我遇到了如何从公共int []数组值中过滤datagridvew的问题。
这是我的代码:
public int[] cartConfirm_lst = new int[20];
public void loadDV()
{
string connStr = "Data Source=731LPTP\\SQLEXPRESS;Initial Catalog=ACCSIS;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand comm = new SqlCommand("SELECT * from Orders");
comm.Connection = conn;
SqlDataReader dr = comm.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
//Code for DataView filter
DataTable filteredTable = dt.Clone();
DataView dv = dt.DefaultView;
foreach(int x in cartConfirm_lst)
dv.RowFilter = "Order_ID in (" + cartConfirm_lst[x] + ")";
filteredTable = dv.ToTable();
cartConfirm_dgv.DataSource = filteredTable;
}
非常感谢任何帮助,谢谢。
答案 0 :(得分:0)
您可以使用RowFilter
(cartConfirm_dgv.DataSource as DataTable).DefaultView.RowFilter = "Order_ID IN (1, 2, 3)"