Datagridview paint issue
I have a datagridview in which I process the data from a datatable. Then change the color on fields that are an issue. I do this through the ProgressChanged event. This is the code:
private void bgwCompare_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
ReportRow rr = (ReportRow)e.UserState;
if (rr.nRow == 1 && rr.nColumn == 2)
rr.nColumn = 2; // If I leave this in it works, if I remove it the single cell is not colored
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
This gets... REALLY bizarre... I only appear to have a problem with a single cell out of over 1000 records.
IF I try to watch the cell get set, it works. (see the above code rr.nRow == 1 && rr.nColumn == 2)
If I comment that code out, the cell doesn't get painted. If I leave that code in, the cell gets painted. I know the value getting set to itself isn't doing anything, I just used that to set a break point. However, if I take the breakpoint off but leave the code it; it works. I'm baffled on what the heck is going on...
Anyone have any ideas?
c# winforms
add a comment |
I have a datagridview in which I process the data from a datatable. Then change the color on fields that are an issue. I do this through the ProgressChanged event. This is the code:
private void bgwCompare_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
ReportRow rr = (ReportRow)e.UserState;
if (rr.nRow == 1 && rr.nColumn == 2)
rr.nColumn = 2; // If I leave this in it works, if I remove it the single cell is not colored
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
This gets... REALLY bizarre... I only appear to have a problem with a single cell out of over 1000 records.
IF I try to watch the cell get set, it works. (see the above code rr.nRow == 1 && rr.nColumn == 2)
If I comment that code out, the cell doesn't get painted. If I leave that code in, the cell gets painted. I know the value getting set to itself isn't doing anything, I just used that to set a break point. However, if I take the breakpoint off but leave the code it; it works. I'm baffled on what the heck is going on...
Anyone have any ideas?
c# winforms
add a comment |
I have a datagridview in which I process the data from a datatable. Then change the color on fields that are an issue. I do this through the ProgressChanged event. This is the code:
private void bgwCompare_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
ReportRow rr = (ReportRow)e.UserState;
if (rr.nRow == 1 && rr.nColumn == 2)
rr.nColumn = 2; // If I leave this in it works, if I remove it the single cell is not colored
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
This gets... REALLY bizarre... I only appear to have a problem with a single cell out of over 1000 records.
IF I try to watch the cell get set, it works. (see the above code rr.nRow == 1 && rr.nColumn == 2)
If I comment that code out, the cell doesn't get painted. If I leave that code in, the cell gets painted. I know the value getting set to itself isn't doing anything, I just used that to set a break point. However, if I take the breakpoint off but leave the code it; it works. I'm baffled on what the heck is going on...
Anyone have any ideas?
c# winforms
I have a datagridview in which I process the data from a datatable. Then change the color on fields that are an issue. I do this through the ProgressChanged event. This is the code:
private void bgwCompare_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
ReportRow rr = (ReportRow)e.UserState;
if (rr.nRow == 1 && rr.nColumn == 2)
rr.nColumn = 2; // If I leave this in it works, if I remove it the single cell is not colored
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
This gets... REALLY bizarre... I only appear to have a problem with a single cell out of over 1000 records.
IF I try to watch the cell get set, it works. (see the above code rr.nRow == 1 && rr.nColumn == 2)
If I comment that code out, the cell doesn't get painted. If I leave that code in, the cell gets painted. I know the value getting set to itself isn't doing anything, I just used that to set a break point. However, if I take the breakpoint off but leave the code it; it works. I'm baffled on what the heck is going on...
Anyone have any ideas?
c# winforms
c# winforms
asked Nov 21 '18 at 4:17
DaBlueDaBlue
753625
753625
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I think that if you comment your line rr.nColumn = 2
out the code will be interpreted as like
if (rr.nRow == 1 && rr.nColumn == 2)
{
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
and then the BackColor on [1,2] is not set as desired.
@DaBlue as you say in the comments no my code is not interpreted like this, please then try the following
if (false)
MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
In this case "2" will be shown and then try out the following code
if (false)
//MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
this time you won't see any pop up
IMHO you should always use curly braces even if it's an "one-liner"
That "one liner" is only for debugging and sets the variable to the same value as it is. As I mentioned (and ironically), this line makes it work. This line is ONLY for debugging purposes so I can set a break point where the data is having an issue in the DGV so I can see it go through the code.
– DaBlue
Nov 21 '18 at 11:20
And no, it wouldn't be interpreted as you have it above.
– DaBlue
Nov 21 '18 at 11:21
1
DaBlue hes right about how your code would be interpreted and also about how you should always use braces. Especially about always using braces LOL
– Scope Creep
Nov 22 '18 at 5:27
I've been coding c/C++/C# for 40 years. Compile and run this and you will see it does work. Best practice has always been 1 line is no brace, multiple uses braces.
– DaBlue
Dec 12 '18 at 16:50
add a comment |
Turns out it was working ok. I restarted my computer and re-ran the project with out the "debug code" and it worked perfectly. There must have been something in the OS that was causing issues.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405179%2fdatagridview-paint-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think that if you comment your line rr.nColumn = 2
out the code will be interpreted as like
if (rr.nRow == 1 && rr.nColumn == 2)
{
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
and then the BackColor on [1,2] is not set as desired.
@DaBlue as you say in the comments no my code is not interpreted like this, please then try the following
if (false)
MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
In this case "2" will be shown and then try out the following code
if (false)
//MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
this time you won't see any pop up
IMHO you should always use curly braces even if it's an "one-liner"
That "one liner" is only for debugging and sets the variable to the same value as it is. As I mentioned (and ironically), this line makes it work. This line is ONLY for debugging purposes so I can set a break point where the data is having an issue in the DGV so I can see it go through the code.
– DaBlue
Nov 21 '18 at 11:20
And no, it wouldn't be interpreted as you have it above.
– DaBlue
Nov 21 '18 at 11:21
1
DaBlue hes right about how your code would be interpreted and also about how you should always use braces. Especially about always using braces LOL
– Scope Creep
Nov 22 '18 at 5:27
I've been coding c/C++/C# for 40 years. Compile and run this and you will see it does work. Best practice has always been 1 line is no brace, multiple uses braces.
– DaBlue
Dec 12 '18 at 16:50
add a comment |
I think that if you comment your line rr.nColumn = 2
out the code will be interpreted as like
if (rr.nRow == 1 && rr.nColumn == 2)
{
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
and then the BackColor on [1,2] is not set as desired.
@DaBlue as you say in the comments no my code is not interpreted like this, please then try the following
if (false)
MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
In this case "2" will be shown and then try out the following code
if (false)
//MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
this time you won't see any pop up
IMHO you should always use curly braces even if it's an "one-liner"
That "one liner" is only for debugging and sets the variable to the same value as it is. As I mentioned (and ironically), this line makes it work. This line is ONLY for debugging purposes so I can set a break point where the data is having an issue in the DGV so I can see it go through the code.
– DaBlue
Nov 21 '18 at 11:20
And no, it wouldn't be interpreted as you have it above.
– DaBlue
Nov 21 '18 at 11:21
1
DaBlue hes right about how your code would be interpreted and also about how you should always use braces. Especially about always using braces LOL
– Scope Creep
Nov 22 '18 at 5:27
I've been coding c/C++/C# for 40 years. Compile and run this and you will see it does work. Best practice has always been 1 line is no brace, multiple uses braces.
– DaBlue
Dec 12 '18 at 16:50
add a comment |
I think that if you comment your line rr.nColumn = 2
out the code will be interpreted as like
if (rr.nRow == 1 && rr.nColumn == 2)
{
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
and then the BackColor on [1,2] is not set as desired.
@DaBlue as you say in the comments no my code is not interpreted like this, please then try the following
if (false)
MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
In this case "2" will be shown and then try out the following code
if (false)
//MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
this time you won't see any pop up
IMHO you should always use curly braces even if it's an "one-liner"
I think that if you comment your line rr.nColumn = 2
out the code will be interpreted as like
if (rr.nRow == 1 && rr.nColumn == 2)
{
if (rr.nColumn == -1)
dgvResults.Rows[rr.nRow].DefaultCellStyle.BackColor = Color.Yellow;
else
dgvResults.Rows[rr.nRow].Cells[rr.nColumn].Style.BackColor = Color.Salmon;
}
and then the BackColor on [1,2] is not set as desired.
@DaBlue as you say in the comments no my code is not interpreted like this, please then try the following
if (false)
MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
In this case "2" will be shown and then try out the following code
if (false)
//MessageBox.Show("1"); // If I leave this in it works, if I remove it the single cell is not colored
if (true)
MessageBox.Show("2");
else
MessageBox.Show("3");
this time you won't see any pop up
IMHO you should always use curly braces even if it's an "one-liner"
edited Dec 15 '18 at 17:20
answered Nov 21 '18 at 9:17
ChrizzleWhizzleChrizzleWhizzle
623
623
That "one liner" is only for debugging and sets the variable to the same value as it is. As I mentioned (and ironically), this line makes it work. This line is ONLY for debugging purposes so I can set a break point where the data is having an issue in the DGV so I can see it go through the code.
– DaBlue
Nov 21 '18 at 11:20
And no, it wouldn't be interpreted as you have it above.
– DaBlue
Nov 21 '18 at 11:21
1
DaBlue hes right about how your code would be interpreted and also about how you should always use braces. Especially about always using braces LOL
– Scope Creep
Nov 22 '18 at 5:27
I've been coding c/C++/C# for 40 years. Compile and run this and you will see it does work. Best practice has always been 1 line is no brace, multiple uses braces.
– DaBlue
Dec 12 '18 at 16:50
add a comment |
That "one liner" is only for debugging and sets the variable to the same value as it is. As I mentioned (and ironically), this line makes it work. This line is ONLY for debugging purposes so I can set a break point where the data is having an issue in the DGV so I can see it go through the code.
– DaBlue
Nov 21 '18 at 11:20
And no, it wouldn't be interpreted as you have it above.
– DaBlue
Nov 21 '18 at 11:21
1
DaBlue hes right about how your code would be interpreted and also about how you should always use braces. Especially about always using braces LOL
– Scope Creep
Nov 22 '18 at 5:27
I've been coding c/C++/C# for 40 years. Compile and run this and you will see it does work. Best practice has always been 1 line is no brace, multiple uses braces.
– DaBlue
Dec 12 '18 at 16:50
That "one liner" is only for debugging and sets the variable to the same value as it is. As I mentioned (and ironically), this line makes it work. This line is ONLY for debugging purposes so I can set a break point where the data is having an issue in the DGV so I can see it go through the code.
– DaBlue
Nov 21 '18 at 11:20
That "one liner" is only for debugging and sets the variable to the same value as it is. As I mentioned (and ironically), this line makes it work. This line is ONLY for debugging purposes so I can set a break point where the data is having an issue in the DGV so I can see it go through the code.
– DaBlue
Nov 21 '18 at 11:20
And no, it wouldn't be interpreted as you have it above.
– DaBlue
Nov 21 '18 at 11:21
And no, it wouldn't be interpreted as you have it above.
– DaBlue
Nov 21 '18 at 11:21
1
1
DaBlue hes right about how your code would be interpreted and also about how you should always use braces. Especially about always using braces LOL
– Scope Creep
Nov 22 '18 at 5:27
DaBlue hes right about how your code would be interpreted and also about how you should always use braces. Especially about always using braces LOL
– Scope Creep
Nov 22 '18 at 5:27
I've been coding c/C++/C# for 40 years. Compile and run this and you will see it does work. Best practice has always been 1 line is no brace, multiple uses braces.
– DaBlue
Dec 12 '18 at 16:50
I've been coding c/C++/C# for 40 years. Compile and run this and you will see it does work. Best practice has always been 1 line is no brace, multiple uses braces.
– DaBlue
Dec 12 '18 at 16:50
add a comment |
Turns out it was working ok. I restarted my computer and re-ran the project with out the "debug code" and it worked perfectly. There must have been something in the OS that was causing issues.
add a comment |
Turns out it was working ok. I restarted my computer and re-ran the project with out the "debug code" and it worked perfectly. There must have been something in the OS that was causing issues.
add a comment |
Turns out it was working ok. I restarted my computer and re-ran the project with out the "debug code" and it worked perfectly. There must have been something in the OS that was causing issues.
Turns out it was working ok. I restarted my computer and re-ran the project with out the "debug code" and it worked perfectly. There must have been something in the OS that was causing issues.
answered Nov 21 '18 at 12:23
DaBlueDaBlue
753625
753625
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405179%2fdatagridview-paint-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown