Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
355
The header checkbox defaults to Indeterminate
posted

...using Infragistics2.Win.UltraWinGrid.v9.2

When I initially load the grid for the first time (the first time that grid.DataBind() is ever called) the header checkbox's state is Indeterminate and it displays as a greyed out checkbox.  This even though the checkbox in the bound column is always false.


I've created a very simple winform to verify this behavior and in that case the checbox begins in an unchecked state just as I'd expect it to: so clearly I'm doing something to cause this behavior, but I have no idea what.

...some data


#region Grid Events

///


/// Handles the MouseDown event of the ugRecvGrid control.
///
///The source of the event.
///The instance containing the event data.
void ugRecvGrid_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
UltraGrid ug = (UltraGrid)sender;
ExportGridExcelEvent(ug, "Receivables");
}
}

private void ugRecvGrid_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e)
{
if (e.Rows != null && e.Rows.Count > 0)
{
this.Cursor = Cursors.WaitCursor;
//I removed the synchronization cause that would cause this method to get called everytime a change was made in
//one of the rows
CheckState currentCheckState = e.Column.GetHeaderCheckedState(e.Rows);
if (currentCheckState != CheckState.Indeterminate)
{
var receivableObjs = e.Rows.Select(r => r.ListObject as ReceivablesDTO).ToArray();

bool willcontinue = true;
string action = (currentCheckState == CheckState.Checked ? "Adding" : "Removing");
if (receivableObjs.Length > 100 && currentCheckState == CheckState.Checked)
{
string title = string.Format("Adding claims for {0:g} recoveries",receivableObjs.Length);
willcontinue = MessageBox.Show("This could take a long a long time.\nContinue?", title, MessageBoxButtons.YesNo) == DialogResult.Yes;
}
if (willcontinue)
{
using (FrmProgress.Show("Retrieving claims...", receivableObjs.Length, false))
{
for (int i = 0; i < receivableObjs.Length; i++)
{
FrmProgress.UpdateMeter(i + 1);
//var cell = row.Cells["IsChecked"];
switch (currentCheckState)
{
case CheckState.Checked:
receivableObjs[i].IsChecked = true;
break;
case CheckState.Unchecked:
receivableObjs[i].IsChecked = false;
break;
}

AddOrRemoveRows(receivableObjs[i].IsChecked, receivableObjs[i]);

}
}
}

}
this.Cursor = Cursors.Default;
}
}

private void ugRecvGrid_CellChange(object sender, CellEventArgs e)
{
//the other CheckStates are handled by ugRecvGrid_AfterHeaderCheckStateChanged
if (e.Cell.Column.GetHeaderCheckedState(e.Cell.Row.ParentCollection) == CheckState.Indeterminate)
{
this.Cursor = Cursors.WaitCursor;
if (e.Cell.Column.Key.Equals("IsChecked"))
{
var rcv = e.Cell.Row.ListObject as ReceivablesDTO;
bool add = false;
bool.TryParse(e.Cell.Text, out add);
//toggle the isChecked value based on the
rcv.IsChecked = add;
AddOrRemoveRows(add, rcv);
}
this.Cursor = Cursors.Default;
}
}

private void ugRecvGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{

//Display a checkbox in the column header, where column's data type isBoolean,DefaultableBoolean, or Nullable Boolean.
var selectorColumn = e.Layout.Bands[0].Columns["IsChecked"];

if (selectorColumn != null)
{
selectorColumn.Header.CheckBoxVisibility = HeaderCheckBoxVisibility.WhenUsingCheckEditor;
//Aligns the Header checkbox to the right of the Header caption
selectorColumn.Header.CheckBoxAlignment = HeaderCheckBoxAlignment.Right;
//The checkbox and the cell values are kept in synch to affect only the RowsCollection
selectorColumn.Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.RowsCollection;
selectorColumn.Header.VisiblePosition = 0;
this.ugRecvGrid.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;
}
if (e.Layout.Bands[0].Summaries == null || e.Layout.Bands[0].Summaries.Count == 0)
SetSummary();
}


///


/// Creates a summary band with totals and row count
private void SetSummary()
{
UltraGridColumn columnToSummarize;
SummarySettings summary;

//PostedAmt
columnToSummarize = ugRecvGrid.DisplayLayout.Bands[0].Columns["PostedAmt"];

summary = ugRecvGrid.DisplayLayout.Bands[0].Summaries.Add("PostedAmt", SummaryType.Sum, columnToSummarize);
summary.DisplayFormat = "{0:c}";
summary.Appearance.TextHAlign = HAlign.Center;

//AdjustedAmt
columnToSummarize = ugRecvGrid.DisplayLayout.Bands[0].Columns["AdjustedAmt"];

summary = ugRecvGrid.DisplayLayout.Bands[0].Summaries.Add("AdjustedAmt", SummaryType.Sum, columnToSummarize);
summary.DisplayFormat = "{0:c}";
summary.Appearance.TextHAlign = HAlign.Center;

//WriteOffAmt
columnToSummarize = ugRecvGrid.DisplayLayout.Bands[0].Columns["WriteOffAmt"];

summary = ugRecvGrid.DisplayLayout.Bands[0].Summaries.Add("WriteOffAmt", SummaryType.Sum, columnToSummarize);
summary.DisplayFormat = "{0:c}";
summary.Appearance.TextHAlign = HAlign.Center;

//ExpGrossAmt
columnToSummarize = ugRecvGrid.DisplayLayout.Bands[0].Columns["ExpGrossAmt"];

summary = ugRecvGrid.DisplayLayout.Bands[0].Summaries.Add("ExpGrossAmt", SummaryType.Sum, columnToSummarize);
summary.DisplayFormat = "{0:c}";
summary.Appearance.TextHAlign = HAlign.Center;

//ExpFeeAmt
columnToSummarize = ugRecvGrid.DisplayLayout.Bands[0].Columns["ExpFeeAmt"];

summary = ugRecvGrid.DisplayLayout.Bands[0].Summaries.Add("ExpFeeAmt", SummaryType.Sum, columnToSummarize);
summary.DisplayFormat = "{0:c}";
summary.Appearance.TextHAlign = HAlign.Center;

//AllocatedAmt
columnToSummarize = ugRecvGrid.DisplayLayout.Bands[0].Columns["AllocatedAmt"];

summary = ugRecvGrid.DisplayLayout.Bands[0].Summaries.Add("AllocatedAmt", SummaryType.Sum, columnToSummarize);
summary.DisplayFormat = "{0:c}";
summary.Appearance.TextHAlign = HAlign.Center;

//row count
columnToSummarize = ugRecvGrid.DisplayLayout.Bands[0].Columns["RecvStatusDesc"];

summary = ugRecvGrid.DisplayLayout.Bands[0].Summaries.Add("RecvStatusDesc", SummaryType.Count, columnToSummarize);
summary.DisplayFormat = "{0:n0}";
summary.Appearance.TextHAlign = HAlign.Center;

ugRecvGrid.DisplayLayout.Bands[0].SummaryFooterCaption = "Totals:";
ugRecvGrid.DisplayLayout.Bands.Layout.Override.SummaryFooterCaptionAppearance.BackColor = Color.DarkSlateBlue;
ugRecvGrid.DisplayLayout.Bands.Layout.Override.SummaryFooterCaptionAppearance.ForeColor = Color.White;
ugRecvGrid.DisplayLayout.Bands.Layout.Override.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
}

#endregion