DataGridView.ColumnStateChanged Event을 처리해야합니다.
myDataTable에서 처음에는 표현식을 설정하지 않습니다. 그리드를 처음로드 한 후 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 이벤트 또는 유사한 검색했습니다. 이제 매력을 발휘합니다. – BastanteCaro