如何防止滚动 datagridView 的前 3 行。
应用程序是带有 net framework 4.5 的 C# windows Forms
最佳答案
属性(property)DataGridViewRow.Frozen Property
应该使用带有 DataGridView
的滚动,唯一要做的就是在 DataGridView.DataBindingComplete
event: like: 中设置它
void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (dataGridView1.Rows.Count >= 3)
{
dataGridView1.Rows[2].Frozen = true;
}
}
您可以将 Rows[2]
设置为卡住,因为从该位置开始的上述行也将卡住。
来自 DataGridViewRow.Frozen Property
This property lets you keep one or several rows of important information in place when a user scrolls through the DataGridView. All rows above the frozen row are also frozen.
将事件添加到您的网格中,例如:
dataGridView1.DataBindingComplete += dataGridView1_DataBindingComplete;
然后数据绑定(bind)如下:
DataTable dt = GetDataFromDB();
dataGridView1.DataSource = dt;
关于c# - 防止滚动前 n 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26038868/