C#datagridview methods to prevent flicker

Source: Internet
Author: User

Description: When you pull the DataGridView scroll bar, it flashes and looks like you're redrawing it, and it doesn't feel good.

WORKAROUND: Use a dual caching mechanism to add a method to the scenario.

Code:

PublicStaticClassExtensionmethods
{
PublicStaticvoidDoubleBuffered (ThisDataGridView DGV,boolSetting
{
Type Dgvtype= DGV. GetType ();
        propertyinfo pi =< Span style= "color: #000000;" > dgvtype.getproperty ( "doublebuffered "              Bindingflags.instance |  bindingflags.nonpublic);
        pi. SetValue (Dgv, setting, null     }
}

< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >< Span style= "color: #000000;" > If DotNetBar control is used DATAGRIDVIEWX

< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >< Span style= "color: #000000;" >public Static class doublebuffered

< Span style= "color: #000000;" >< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >< /span>

< Span style= "color: #000000;" >< Span style= "color: #000000;" >< Span style= "color: #000000;" >public static void DoubleBuffered (Datagridviewx DGV, BOOL setting)

< Span style= "color: #000000;" >< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >< /span>

< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >< Span style= "color: #000000;" >type dgvtype = DGV. GetType ();

< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >< Span style= "color: #0000ff;" >propertyinfo pi = Dgvtype.getproperty ("doublebuffered", bindingflags.instance| BindingFlags.NonPublic)

< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >< Span style= "color: #000000;" >pi. SetValue (dgv,setting,null);

< Span style= "color: #000000;" >< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >

< Span style= "color: #000000;" >< Span style= "color: #0000ff;" >< Span style= "color: #000000;" >

C#datagridview ways to prevent flicker

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.