【问题标题】:DataTable Expressions And Datagrid VisibilityDataTable 表达式和 Datagrid 可见性
【发布时间】:2010-12-15 16:47:51
【问题描述】:

我想知道是否可以仅在 datagridview 的可见列。

这是一个用例。 最终用户有一个填充了最多十列数字的 DataGridView 和一个包含总数的最终列。如果用户决定隐藏这些列之一(理想情况下),则表达式将根据数据网格中的可见列而改变。

感谢您的任何意见。

【问题讨论】:

    标签: c# .net datagridview datatable expression


    【解决方案1】:

    您需要处理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();
    }
    

    【讨论】:

    • 太完美了,谢谢。我正在搜索 ColumnVisible 事件或类似事件。现在很有魅力。
    猜你喜欢
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2015-10-03
    • 2018-07-15
    • 2011-12-04
    • 2020-02-19
    • 1970-01-01
    相关资源
    最近更新 更多