如何对DataGridView.DataSource = DataSet上的数据进行排序或过滤 [英] How to sort or filter data on DataGridView.DataSource=DataSet

查看:406
本文介绍了如何对DataGridView.DataSource = DataSet上的数据进行排序或过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有B.Items用作字段或标准排序并过滤 A.Column [j]

I have B.Items to use as field or criteria sort and filter A.Column[j]

public void sorting(DataGridView A, ComboBox B, string Column)
        {
            query = "Select * from schTable ";
            static string path = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\dBase.accdb";
            OleDbCommand cmd = new OleDbCommand();
            OleDbDataAdapter adt = new OleDbDataAdapter();
            OleDbConnection con = new OleDbConnection(path);
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();

            DataObjectsInitialization();
            con.Open();
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = query;
            adt.SelectCommand = cmd;
            adt.SelectCommand.ExecuteNonQuery();
            con.Close();
            adt.Fill(ds);
            dt = ds.Tables[0];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i].Cells[Column].Value.Equals(B.SelectedItem))
                {
                  //A.Clear();
                  //A.Rows.Add(dt.Rows[i].Cells[Column]);
                }
            }
        }



来自 dt = ds.Tables [0]; 我的代码不再通讯了;如果你可以帮助我,所有的乐趣将是我的:

1.像DataGridView一样访问DataTable。

2.在DataSource运行时清除或删除DataGridView中的行等于dataBase?

谢谢。


From dt = ds.Tables[0]; my codes do not communicate anymore; all pleasure will be mine if you can assist me to:
1. Access the DataTable like DataGridView.
2. Clear or delete rows from DataGridView at run time while the DataSource equals dataBase?
Thank you.

推荐答案

DataView dv = new DataView(ds.Tables[0], "Price > 19", "Price Desc", DataViewRowState.CurrentRows);
dataGridView1.DataSource = dv;





使用dataview



Use dataview


这篇关于如何对DataGridView.DataSource = DataSet上的数据进行排序或过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆