Hi everyone, a friend of mine is trying to remove items from a dataGridView that have a calculated value of less than a given number OR which are blank. The numbers are calculated based on the difference in days in a column and todays date and placed in an unbound column. He can't seem go figure out what the issue is, so a few days ago he asked me to look at it for him. Maybe it's me, but I just don't see anything wrong with the code... I thought maybe another set of eyes would maybe see something that we're missing... He's working in C# 2.0. If you need anything else, please let me know. Here is the applicable code:
If I change the code to remove only values that are not null or "", it works. If it tries to remove values that are not null, "", or less than 30 though, it has trouble. I do not get or receive any sort of error. But values under 30 are included. Breakpoints have not showed anything that showed me there was a problem... Code execution does however appear to end after this if statement, so... Does anyone happen to see where the issue may be? Any help would be greatly appreciated. I had hoped I would be able to help him... I'll give credit of course to whoever helps, I may even be able to then get him to sign up for Neowin... LOL
Question
M_Lyons10
Hi everyone, a friend of mine is trying to remove items from a dataGridView that have a calculated value of less than a given number OR which are blank. The numbers are calculated based on the difference in days in a column and todays date and placed in an unbound column. He can't seem go figure out what the issue is, so a few days ago he asked me to look at it for him. Maybe it's me, but I just don't see anything wrong with the code... I thought maybe another set of eyes would maybe see something that we're missing... He's working in C# 2.0. If you need anything else, please let me know. Here is the applicable code:
// remove the rows that aren't "missing"
for (int i = RDGV1.Rows.Count - 1; i >= 0; i--)
{
if (RDGV1.Rows.Cells[10].Value != null ||
RDGV1.Rows.Cells[10].Value.ToString() != "" ||
double.Parse(RDGV1.Rows.Cells[10].Value.ToString()) >= 30)
{
RDGV1.Rows.RemoveAt(i);
}
}
If I change the code to remove only values that are not null or "", it works. If it tries to remove values that are not null, "", or less than 30 though, it has trouble. I do not get or receive any sort of error. But values under 30 are included. Breakpoints have not showed anything that showed me there was a problem... Code execution does however appear to end after this if statement, so... Does anyone happen to see where the issue may be? Any help would be greatly appreciated. I had hoped I would be able to help him... I'll give credit of course to whoever helps, I may even be able to then get him to sign up for Neowin... LOL
Thanks Again,
Link to comment
https://www.neowin.net/forum/topic/792030-remove-items-from-a-datagridview-issue/Share on other sites
4 answers to this question
Recommended Posts