DataGridView 将冻结列放置在最右侧

发布于 2024-09-12 21:14:14 字数 360 浏览 5 评论 0原文

我在 WinForms 2.0 应用程序中有一个 DataGridView,它有很多列,即使最大化,用户也必须滚动才能看到所有列。最右栏是删除按钮。我们希望始终显示删除按钮,而用户无需水平滚动。

当我尝试设置column.Frozen = true;时,它会删除我的水平滚动条并使所有先前的列冻结。根据 Microsoft 这是由设计。

有人有解决方案吗?

I have a DataGridView in a WinForms 2.0 App that has a lot of columns, enough that even when maximized the user has to scroll to see all columns. The far right column is a delete button. We want to always display the delete button without the user having to horizontally scroll.

When I try setting column.Frozen = true; it removes my horizontal scrollbar and makes all of the previous columns frozen. According to Microsoft this is by design.

Does anyone have a solution for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

虚拟世界 2024-09-19 21:14:14

这是 VS 2005 的错误报告: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=117002&wa=wsignin1.0#

看起来微软并不关心纠正这个问题。 “按设计”?真是个笑话。

This is a bug report for VS 2005: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=117002&wa=wsignin1.0#

It looks like Microsoft doesnt care to correct the issue. "By design"? What a joke.

梦归所梦 2024-09-19 21:14:14

试试这个:

 var cols = dcols.ToArray();//dcols is the DataGridViewColumn List wait to add to DataGridView
    if (cols.Last().Frozen)
    {
        _this.RightToLeft = RightToLeft.Yes;
        cols = cols.Reverse().ToArray();
    } 
    _this.Columns.AddRange(cols);
    //Note that DataGridView does not allow freezing on both sides at the same time, or freezing some columns in the middle.

你会遇到问题。滚动条将位于最右侧。然后,您可以尝试以下代码:

//OnDataBindingComplete
        if (this.Columns.Count > 0)
            this.FirstDisplayedScrollingColumnIndex = this.Columns.Count - 1;

try this:

 var cols = dcols.ToArray();//dcols is the DataGridViewColumn List wait to add to DataGridView
    if (cols.Last().Frozen)
    {
        _this.RightToLeft = RightToLeft.Yes;
        cols = cols.Reverse().ToArray();
    } 
    _this.Columns.AddRange(cols);
    //Note that DataGridView does not allow freezing on both sides at the same time, or freezing some columns in the middle.

You will have a problem. The scrollbar will be positioned to the far right. Then, you can try the code below:

//OnDataBindingComplete
        if (this.Columns.Count > 0)
            this.FirstDisplayedScrollingColumnIndex = this.Columns.Count - 1;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文