M_Mogharrabi,
如果我理解你想怎么做,这可能对你有用。
每当您将数据绑定到 UltraGrid 时,IntializeLayout
每次都会触发该事件,因此您需要确保将摘要行设置为在InitializeLayout
函数中可见。
像这样:
private void yourUltraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
// Define Global settings like you usually do
// ....
// Configure your UltraGrid columns.
//// ID
//// Caption: "ID"
e.Layout.Bands[0].Columns[ColumnKeyA].Header.Caption = "ID";
e.Layout.Bands[0].Columns[ColumnKeyA].Header.VisiblePosition = 0;
e.Layout.Bands[0].Columns[ColumnKeyA].Width = 50;
// Any additional settings you may want for this column.
// Repeat for each column...
// Then add this block under each column you want to add Summary value to.
// This if function is critical to avoid summary rows from duplicating itself.
// Check to see if the Summary does not exist.
if (!e.Layout.Bands[0].Summaries.Exists("yourSummaryKey"))
{
// If it doesn't exist, create the summary.
SummarySettings summary;
summary = e.Layout.Bands[0].Summaries.Add("yourSummaryKey", SummaryType.Sum,
e.Layout.Bands[0].Columns[ColumnKeyA]);
// Change the Display Formatting if you desire.
// This display format will change it to just numbers
// instead of "Sum = 1234"
summary.DisplayFormat = "{0}";
// Change the horizontal alignment for the cell text.
summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Left;
// Apply any other settings to this summary column
// if needed.
// ...
}
}
注意:摘要行仅适用于父波段。无法为子乐队设置摘要行。
如果要重置数据网格,请将以下内容添加到代码中(但不在 InitializeLayout 函数中)
private void btnReset_Click(object sender, EventArgs e)
{
yourUltraGrid.DeleteSelectedRows();
// This will trigger the yourUltraGrid_InitializeLayout event
// and will ensure the column settings are defined.
yourUltraGrid.DataSource = Prototype.ugGetResourcePlanning();
}
这将保留对排序算法所做的任何更改。所以在这个例子中:如果用户对 UltraGrid 进行了任何更改并随之更改了排序算法。点击“重置”按钮只会恢复数据,不会恢复排序算法。
希望这可以帮助。