【发布时间】:2010-12-15 16:47:51
【问题描述】:
我想知道是否可以仅在 datagridview 的可见列。
这是一个用例。 最终用户有一个填充了最多十列数字的 DataGridView 和一个包含总数的最终列。如果用户决定隐藏这些列之一(理想情况下),则表达式将根据数据网格中的可见列而改变。
感谢您的任何意见。
【问题讨论】:
标签: c# .net datagridview datatable expression
我想知道是否可以仅在 datagridview 的可见列。
这是一个用例。 最终用户有一个填充了最多十列数字的 DataGridView 和一个包含总数的最终列。如果用户决定隐藏这些列之一(理想情况下),则表达式将根据数据网格中的可见列而改变。
感谢您的任何意见。
【问题讨论】:
标签: c# .net datagridview datatable expression
您需要处理DataGridView.ColumnStateChanged Event。
在 myDataTable 中,起初您没有设置任何表达式。 首次加载 Grid 后,启动 recalculateTotalExpression。
void recalculateTotalExpression()
{
// 0. Create a StringBuilder for your new Expression.
// 1. Go through each of the columns of your datagridview, except the TotalColumn
// 2. Foreach Visible DataGridView Column, add the corresponding DataTable column to the expression.
// 3. Set the Expression to the TotalColumn : TotalColumn.Expression = sb.toString();
}
void MyDataGridView_OnColumnStateChanged(DataGridViewColumnStateChangedEventArgs e)
{
recalculateTotalExpression();
}
【讨论】: