Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Displaying rows in first column (index 0) where cells match a particular date

$
0
0

How would I hide all rows on my dataGridView that do not match the date of "27/10/2013" by comparing it with whatever is in the DatePaid column. I have checked my mdb database (which I'm pulling the data from) and DataPaid has a datatype of ShortText, so no conversion is necessary.

Currently the code below hides all my rows. 

        public void viewOverdue_Click(object sender, EventArgs e)
        {
            viewOverdue.ForeColor = Color.Red;
            viewHistory.ForeColor = Color.Black;
            viewHire.ForeColor = Color.Black;
            viewRent.ForeColor = Color.Black;

            CurrencyManager manager = (CurrencyManager)BindingContext[dataGridView1.DataSource];
            manager.SuspendBinding();
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (!string.Equals(row.Cells[0].Value.ToString(), "27/10/2013", StringComparison.OrdinalIgnoreCase))
                {
                    row.Visible = false;
                }
                else
                {
                    row.Visible = true;
                }
            }
            manager.ResumeBinding();
        }




Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>