TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bagzli
NA
36
23.2k
Removing Rows from DataGridView
Aug 22 2012 9:44 PM
Hello,
I'm having a really messed up problem that I cannot seem to fix. Any help is appreciated.
So here is the method:
dgvLoadDetails = DataGridView that I'm using.
dtpFrom = DateTimePicker - Where my range starts
dtpTo = DateTimePicker - Where my range ends
Method:
It goes into grid view and grabs the cell that holds the dates and checks by each row if the date in that cell is between the range of Date From and Date To. If its not between the range of those dates it removes the row.
My Problem, it does all this but it does not removes every row, I have to click run this method few times in order to filter it entirelly. First time i run it, it removes 2 records, second time it removes 1 record, it never removes all records and I have no idea why.
Data Grid View is linked to a DataSet from Microsoft Access Database file (.mdb)
If you guys can point out my mistake or tell me a better way to do this, basically all I want is to filter the records between certain dates.
for (int i = 0; i < dgvLoadDetails.RowCount; i++)
{
DataGridViewRow row = dgvLoadDetails.Rows[i];
DateTime currentDate = Convert.ToDateTime(row.Cells[2].Value.ToString());
if (currentDate.Date < Convert.ToDateTime(dtpFrom.Text) || currentDate.Date > Convert.ToDateTime(dtpTo.Text))
{
dgvLoadDetails.Rows.Remove(row);
}
}
Reply
Answers (
4
)
VSTO Query
How do I change my win7 admin password using C#?