在对datagridview使用双缓存时,出现扩展方法必须在非泛型静态类中定义,我对这个不太理解,请解
 {
        public Form6()
        {
            InitializeComponent();
            Type type = dataGridView1.GetType(); PropertyInfo pi = type.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(dataGridView1, true, null);
        }
        public static void SetDoubleBuffered(this DataGridView dgv, bool b)
        {
            var dgvType = dgv.GetType();
            var pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
            pi.SetValue(dgv, b, null);
        } 

解决方案 »

  1.   

    static class DataGridViewExtension
    {
      public static void SetDoubleBuffered(this DataGridView dgv, bool b)
      {
         //...
      }
    }
      

  2.   

    谢谢楼上的大哥,另外我想重写DATAGRIDVIEW,给它加一个边框代码如下
    protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, this.StateCommon.DataCell.Border.Color1, 1, ButtonBorderStyle.Solid, this.StateCommon.DataCell.Border.Color1, 1, ButtonBorderStyle.Solid, this.StateCommon.DataCell.Border.Color1, 1, ButtonBorderStyle.Solid, this.StateCommon.DataCell.Border.Color1, 1, ButtonBorderStyle.Solid);        }
    如果拖动水平滚动条,就出现无数的线条。应问应该如何做,谢谢了