Datagridview paint issue












-1















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?










share|improve this question



























    -1















    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?










    share|improve this question

























      -1












      -1








      -1








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 4:17









      DaBlueDaBlue

      724625




      724625
























          2 Answers
          2






          active

          oldest

          votes


















          1














          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"






          share|improve this answer


























          • 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



















          0














          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.






          share|improve this answer























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            1














            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"






            share|improve this answer


























            • 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
















            1














            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"






            share|improve this answer


























            • 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














            1












            1








            1







            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"






            share|improve this answer















            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"







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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



















            • 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













            0














            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.






            share|improve this answer




























              0














              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.






              share|improve this answer


























                0












                0








                0







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 12:23









                DaBlueDaBlue

                724625




                724625






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]