[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 716
  • Last Modified:

How do I limit the number of a DataGridView's PostPaint events?

This function is working:

        private void ordersDataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            if (handles.DriverList != null && handles.DriverList.Count > 0 && ordersDataGridView.Rows.Count > e.RowIndex)
            {
                DataGridViewRow dgvr = ordersDataGridView.Rows[e.RowIndex];
                if (dgvr != null && handles.Scenario.IsFinalRowInRunSelected(dgvr))
                {
                    e.Graphics.DrawLine(Pens.Black, e.RowBounds.Left, e.RowBounds.Bottom - 1, e.RowBounds.Right, e.RowBounds.Bottom - 1);
                }
            }
        }

but when running in the debugger, it calls it repeatedly passing in the same e.RowIndex. Is that the effect of the debugger? Or should I be changing the value of the input parameter to get Windows to stop calling this event?

I'm really curious.

Thanks,
newbieweb
0
newbieweb
Asked:
newbieweb
  • 2
  • 2
2 Solutions
 
RameshSCommented:
When you debug the application in VS, VS is open the source code window to show the break point and switch to application window to show the output  if press F5 or F10. Obviously the paint event is occuring there. Becuase the paint event is related windows OS based. It will happen whenever the  the content of a control/output  is drawn in the screen. When switching between source code editor and application's output  window, the paint event fires recursively.

I created DataGridView with 3 columns. Also i created datatable with 3 rows and bind it to DataGridView. I displayed the value e.RowIndex in output window using the following code.

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Post Paint Event" + e.RowIndex.ToString());              
        }

It displayed the following output.
Post Paint Event 0
Post Paint Event 1
Post Paint Event 2
Post Paint Event 3
Post Paint Event 0
Post Paint Event 1
Post Paint Event 2
Post Paint Event 3
Post Paint Event 0

Hence it ifred 9 times(imay for 3 rows and 3 columns). But when i debug or display the e.RowIndex in a MessageBox, the event fired many times.
0
 
newbiewebSr. Software EngineerAuthor Commented:
How do I view the output inside Visual Studio?
0
 
RameshSCommented:
In VS 2005/2008, Click Debug menu->Windows->Output.
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks. This is a super powerful debugging tool I never used before.

And thanks for explaining why the PostEvent fired so many times.

newbieweb
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now