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
newbiewebSr. Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.