简体   繁体   English

按datetimepicker值C#过滤访问已填充的dataGridView

[英]Filter Access filled dataGridView by datetimepicker value C#

Using my code below, I want to modify it so the dataGridView (dgReceived) is filtered by the "dateTimePicker1" (shown in the picture). 使用下面的代码,我想对其进行修改,以便dataGridView(dgReceived)被“ dateTimePicker1”(如图所示)过滤。 It works great to retrieve data from the ACCESS database, but I need to add that filter functionality. ACCESS数据库检索数据非常有用,但是我需要添加该过滤器功能。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace dataGridView
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Query Form\Database.accdb");
            vcon.Open();
            DataSet ds = new DataSet();
            OleDbDataAdapter daReceived = new OleDbDataAdapter();

            OleDbCommand slctReceived = new OleDbCommand("SELECT * FROM script_Received", vcon);
            daReceived.SelectCommand = slctReceived;
            daReceived.Fill(ds, "tblReceived");

            dgReceived.DataSource = ds.Tables["tblReceived"];


        }

        private void dgReceived_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

You can filter with a BindingSource which will sit between the table and the DGV's DataSource. 您可以使用位于表和DGV的数据源之间的BindingSource进行过滤。

It has a Filter property that you use to filter data. 它具有用于过滤数据的Filter属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM