Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:47:40+00:00 2026-05-31T11:47:40+00:00

I’m trying to filter a deadline column in a datagridview by 2 datetimepickers –

  • 0

I’m trying to filter a deadline column in a datagridview by 2 datetimepickers – startDate and endDate.

datagridview is TaskTable2,
datetimepicker1 is startSchedule,
datetimepicker2 is endSchedule and
deadline in datagridview is deadlineRow

So far I have got the following code which is successfully making the rows invisible which are not between the selected start and end date.

private void scheduleButton_Click(object sender, EventArgs e)
    {

        DateTime startSchedule = startDate.Value.Date;
        DateTime endSchedule = endDate.Value.Date;

        if (startSchedule <= endSchedule)// runs foreach loop if startdate and enddate are valid
        {
            foreach (DataGridViewRow dr in TaskTable2.Rows)// loops through rows of datagridview
            {
                string deadline = dr.Cells["Deadline"].Value.ToString(); // gets deadline values
                DateTime deadlineRow = Convert.ToDateTime(deadline); // converts deadline string to datetime and stores in deadlineRow variable

                if (startSchedule <= deadlineRow && deadlineRow <= endSchedule) // filters deadlines that are => startDate and <= endDate
                {
                    dr.Visible = true; // display filtered rows here.
                }
                else
                {
                    dr.Visible = false; // hide rows that are not beteen start and end date.
                }

            }
        }
        else
        {     
            MessageBox.Show("Please ensure Start Date is set before End Date."); // ensures user selects an end date after the start date.
        }
    }

However, I have a few existing problems:

  1. The application crashes and I get the following error when I select a date range that will display no tasks:

‘Row associated with the currency manager’s position cannot be made invisible’

  1. I have a print button that is supposed to print the filtered results.
    However, it is printing all data stored in the datagridview, even if some rows are visible=false from pressing the schedule button so I’m guessing I need to use a different approach to remove the rows rather than hide them.

The datagridview is bound to an XML file so data can be removed from the datagridview for filtering and printing aslong as they remain in the XML file.

Any help would be greatly appreciated!

Thankyou

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:47:41+00:00Added an answer on May 31, 2026 at 11:47 am

    I would use the Filter property on the bindingsource for the datagridview. The Filter property allows you to view a subset of the DataSource.

    Example from MSDN:

    private void PopulateDataViewAndFilter()
    {
        DataSet set1 = new DataSet();
    
        // Some xml data to populate the DataSet with.
        string musicXml =
            "<?xml version='1.0' encoding='UTF-8'?>" +
            "<music>" +
            "<recording><artist>Coldplay</artist><cd>X&amp;Y</cd></recording>" +
            "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" +
            "<recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>" +
            "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" +
            "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" +
            "</music>";
    
        // Read the xml.
        StringReader reader = new StringReader(musicXml);
        set1.ReadXml(reader);
    
        // Get a DataView of the table contained in the dataset.
        DataTableCollection tables = set1.Tables;
        DataView view1 = new DataView(tables[0]);
    
        // Create a DataGridView control and add it to the form.
        DataGridView datagridview1 = new DataGridView();
        datagridview1.AutoGenerateColumns = true;
        this.Controls.Add(datagridview1);
    
        // Create a BindingSource and set its DataSource property to
        // the DataView.
        BindingSource source1 = new BindingSource();
        source1.DataSource = view1;
    
        // Set the data source for the DataGridView.
        datagridview1.DataSource = source1;
    
        //The Filter string can include Boolean expressions.
        source1.Filter = "artist = 'Dave Matthews' OR cd = 'Tigerlily'";
    }
    

    I use this type of Filter to show data based on account. For an account, I have a textbox when the user places the account number and I use the TextChanged Event to apply the filter. Then I have a button that is used to remove the Filter from the binding source.

    If you want to filter by date you can following instructions in this SO question:

    BindingSource Filter by date

    Using the filter on a date that is not present should not crash the app, it will just display nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.