是否可以将 DataGridView
的最后一行作为列的总和,并且最后一行始终显示/卡住?
最佳答案
解决方案其实很简单,只需要你跳出框框思考一下。
通常,一旦数据加载到您的 GridView 中,它的底部就会出现一个深灰色的行:
您可以充分利用这个空间。您需要做的就是将几个标签拖到您的表单上,放置在您的 GridView 中,并应用背景颜色:
在您的代码中,添加如下方法:
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");
}
然后,无论您在哪里更新 GridView ,调用 UpdateTotal(labelPostsAffected, 2000);
,使用您的标签名称和您计算的总和(或在方法中计算) ).
结果是这样的:
关于c# - 将 DataGridView 的最后一行卡住为列的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2391663/