c# - 防止滚动前 n 行

标签 c# .net datagridview

如何防止滚动 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/

相关文章:

c# - StringBuilder.Append with float

c# - 在安装过程中选择 ClickOnce 应用程序的安装路径

asp.net - 如何强制Azure上的Web应用程序与.net Framework 4.5.2一起使用?

c# - 使用 DataGridViewCheckBoxColumn 更新 DatagridView

c# - 结合两个不同类型的序列

c# - 如何让 Debug.WriteLine 在 Release 模式下写入输出窗口?

javascript - 为什么 HTML 按钮的“属性”窗口中没有“事件”按钮?

vb.net - 以编程方式根据 gridview 值选择一行

c# 如何在 SQL 查询中为 From 子句使用 Combobox.Value

c# - C#中的线程错误