gpt4 book ai didi

c# - 在 DataGridView 中将最后一行设置为 Frozen

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:45 25 4
gpt4 key购买 nike

我的网格目前有 40 行。一次只能显示 20 行,因此网格有滚动条。

我想卡住 DataGridView 的最后一行,但随后滚动条消失了。如何解决?

最佳答案

您正在使用 DataGridviewRow.Frozen 属性:请参阅文档 here .

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.

这实际上意味着,如果您“卡住”最后一行,则卡住行上方的所有行也会被卡住;这意味着滚动条被移除,因为你卡住了最后一行。

回答你的问题;您不能单独“卡住”最后一行,这不是Frozen 属性的本质。


this document 中记录了一个解决方法.但是,它是在 VB 中,因此您必须自己将其转换为 C#。

实际上我进一步寻找发现this document ,其中有一个 C# 中的小示例。它似乎有错误,但可能会让你朝着你的目标前进。

public partial class MyDataGridView : DataGridView
{
public StatusStrip Footer
{
get { return (StatusStrip)this.Controls["Footer"]; }
}

private bool _footerVisible;
[Browsable(false)]
///

/// Sets or Gets the value specifying if a footer bar is shown or not
///

public bool FooterVisible
{
get { return _footerVisible; }
set
{
_footerVisible = value;
this.Controls["Footer"].Visible = _footerVisible;
}
}

public MyDataGridView()
{
InitializeComponent();
StatusStrip footer = new StatusStrip();
footer.Name = "Footer";
footer.ForeColor = Color.Black;

this.Controls.Add(footer);
((StatusStrip)this.Controls["Footer"]).Visible = _footerVisible;
((StatusStrip)this.Controls["Footer"]).VisibleChanged += new EventHandler(RDataGridView_VisibleChanged);
this.Scroll += new ScrollEventHandler(RDataGridView_Scroll);
_footerItems = ((StatusStrip)this.Controls["Footer"]).Items;
}
}

上述代码可用作用户控件并继承自DataGridView。然后它会添加一个页脚,您可以在其中填充您选择的最后一行。如果将所有行的 Frozen 属性设置为 False,滚动条仍然可见。

关于c# - 在 DataGridView 中将最后一行设置为 Frozen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24286495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com