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
1145
Select All Header Checkboxes?
posted

Version 9.2 - All 30+ column headers in our grid have header checkboxes (HeaderCheckBoxVisibility.Always).  I have been searching (for way to long) to provide a way for a user's action to programmatically select (set the CheckedState to Checked) on all columns.  The default is to have all column header checkboxes unchecked as 70% of the time the users will be selecting (checking) only a handful of columns.  So this question is for the other 30% of the time where they only want a small number of columns unchecked thus saving them some serious mouse clicking.

The trigger for this is ready, Thanks in advance!:

 private void gridBuySell_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e)

 

{

 

 

 

 

 

switch (e.Column.GetHeaderCheckedState(e.Rows))

{

 

 

case CheckState.Checked:

 

if (e.Column.Header.Caption == "Exclude All")

 

{

 

 

 

 

foreach()

{

 

//Need to check all column header checkboxes

 

 

 

 

 

 

 c.Column.Header = CheckState.Checked;

}

}

 

 

break;

 

 

case CheckState.Indeterminate:

 

 

break;

 

 

case CheckState.Unchecked:

 

 

//Need to uncheck all column header checkboxes

 

break;

 

 

default:

 

 

break;

}

}

 

A second question is how can we post code so its format look proper in this forum?

 

Parents
  • 6158
    Verified Answer
    Offline posted

    Hello,

    Based on the scenario you described, you will need to call SetHeaderCheckedState() on all the other columns when the "Exclude All" column changes CheckState. Try the following code in the AfterHeaderCheckStateChanged event handler to see if it suites your needs:

     

                UltraGridColumn column = e.Column;
                if (column.Key == "Exclude All")
                {
                    CheckState newCheckState = column.GetHeaderCheckedState(e.Rows);
                    switch (newCheckState)
                    {
                        case CheckState.Checked:
                        case CheckState.Unchecked:
                            ColumnsCollection columns = column.Band.Columns;
                            foreach (UltraGridColumn siblingColumn in columns)
                            {
                                if (siblingColumn == column)
                                    continue;
                                siblingColumn.SetHeaderCheckedState(e.Rows, newCheckState);
                            }
                            break;
                        default:
                            break;
                    }
                }
    

    As far as posting code in the forums is concerned, you'll need to encapsulate your code within "preformatting" tags such as <pre class="c#:nogutter" name="code" > </p>

    Let me know if you any require further assistance with this.

    Thanks,

    Chris

Reply Children
No Data