locked
Cell values being painted multiple times resulting in black unreadable mess RRS feed

  • Question

  • I have a datagridview with an ado.net datasource. The visibility of various columns is set when the form is first show. In the scenario I am investigating the first column shows the email address and the second column shows the full name. When I make any attempt to resize the form the full name column is repainted multiple times with a slight offset and the result is an unreadable mess.

    I have investigated and cannot find a cause. I have be able to work around it by controlling the e.Handled parameter of the CellPaint but how do I know that a resize has started and finished. 


    Mike VE

    Thursday, January 5, 2017 10:40 AM

Answers

  • Thanks for the replies Karen and Bob. I looked at both your suggestions but they did not make any difference. However, they did encourage me to look into some other avenues and I finally tracked what was going on. The Column with the strange behaviour had the backcolor of its default cell style set to Transparent. Setting it back to White like the others cured the strange behaviour. I do not have any notes explaining why I had set it  to Transparent but I'll stick with White for now.

    Thanks for your help.


    Mike VE

    • Marked as answer by Mike VE Friday, January 6, 2017 8:48 AM
    Friday, January 6, 2017 8:48 AM

All replies

  • Hello,

    By chance are you subscribed to CellFormatting event? If so, this could be a place that could cause multiple repaints/flickering.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 5, 2017 1:25 PM
  • Hi,

    Try to set DoubleBuffered of datagridview to reduce flickering.

    PropertyInfo pro = dataGridView1.GetType().GetProperty("DoubleBuffered",BindingFlags.Instance | BindingFlags.NonPublic);
    pro.SetValue(this.dataGridView1, true, null);

    Hope this can be helpful to you.

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 6, 2017 3:10 AM
  • Thanks for the replies Karen and Bob. I looked at both your suggestions but they did not make any difference. However, they did encourage me to look into some other avenues and I finally tracked what was going on. The Column with the strange behaviour had the backcolor of its default cell style set to Transparent. Setting it back to White like the others cured the strange behaviour. I do not have any notes explaining why I had set it  to Transparent but I'll stick with White for now.

    Thanks for your help.


    Mike VE

    • Marked as answer by Mike VE Friday, January 6, 2017 8:48 AM
    Friday, January 6, 2017 8:48 AM