冻结的DataGridView的最后一行作为列的总和? [英] Frozen last row of DataGridView as the sum of the columns?

查看:197
本文介绍了冻结的DataGridView的最后一行作为列的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能作出的最后一排一个的DataGridView 作为列的总和,而最后一行始终会显示/冻结?

Is it possible to make the last row of a DataGridView as the sum of the columns, and that the last row always will show/be frozen?

推荐答案

解决的办法其实很简单,只需要你条条框框一点。

The solution is actually very simple, and just requires you to think outside the box a little.

通常情况下,一旦数据被加载到网格视图中,有一个暗灰色排在它的底部:

Usually, once data is loaded into your grid view, there's a dark grey row at the bottom of it:

您可以使用这个空间,你的优势。所有你需要做的就是拖几个标签到您的形式,放在刚网格视图中,应用了背景颜色:

You can use this space to your advantage. All you need to do is drag a few labels onto your form, placed just inside your grid view, with a background colour applied:

在你的code,添加一个方法是这样的:

Within your code, add a method like this:

void UpdateTotal(Label Label, int Number)
{
    // Called from another thread; facilitate safe cross-thread operation
    if(this.InvokeRequired)
        this.Invoke(new Action<Label, int>(UpdateTotal), new object[] {Label, Number});

    // Called from this thread or invoked
    else
        // Format the number with a thousands separator
        Label.Text = Number.ToString("N0");
}

然后,无论你更新你的网格视图,叫 UpdateTotal(labelPostsAffected,2000); ,使用标签的名称,你已经计算出的总和(或者计算它的方法)。

Then, from wherever you update your grid view, call UpdateTotal(labelPostsAffected, 2000);, using the name of your label, and the sum you've calculated (or calculate it in the method).

结果是这样的:

这篇关于冻结的DataGridView的最后一行作为列的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆