我正在尝试让我的数据网格视图在滚动时看起来更好,因为它看起来像是我使用的是2000年甚至更糟的pc。在搜索的过程中,我偶然发现了DoubleBuffered方法,每个人都说它能让事情变得更好。
当我使用它时,dataGridView2.DoubleBuffered(true)行变红并显示错误消息: CS1955 C#不可调用成员不能像方法一样使用。此处无法访问受保护的属性“”DoubleBuffered“”。“
如果你不能帮助我解决这个错误,也许可以告诉我一个让滚动更流畅的方法。
using System.Windows.Forms;
using System.Data.OleDb;
using System.Reflection;
namespace WarehouseManagementToolv1
{
public partial class OrdersForm : Form
{
public SecondaryCallDB.GetDatabase _GetDatabase;
private OleDbConnection connection = new OleDbConnection();
public OrdersForm()
{
InitializeComponent();
_GetDatabase = new SecondaryCallDB.GetDatabase();
}
private void btnLoadTable_Click_1(object sender, EventArgs e)
{
dataGridView2.DataSource = _GetDatabase.GetFullOrderDatabase();
dataGridView2.DoubleBuffered(true);
}
public void DoubleBuffered(DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
}发布于 2019-11-06 18:58:00
您应该将此方法放在静态类中,并通过执行以下操作将其转换为扩展方法
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}或者,您应该像调用普通方法一样调用该方法。
DoubleBuffered(dataGridView2, true)https://stackoverflow.com/questions/58727595
复制相似问题