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
463
Checkbox on Column Header
posted

Hi

I am having some problems in implementing checkboxes on some columns in grid. Here is the scene:

I have a grid with 15 columns, out of which 4 are of type boolean, ie. they accept True/False. Say, we name these columns as A,B,C and D.

I want to have a checkbox on header row for these 4 columns. And my requirement is that when I click on that checkbox, it will make all the currently filtered rows as True (or false if unchecked).

Note, I do not want to apply the True/False on all Rows, but on only the currently visible rows after filter on some other column value.

I am writing this code in initialize event:

e.Layout.Bands[0].Columns["A"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always;

e.Layout.Bands[0].Columns["A"].Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization .None;

and manually (using loop) making the column values True/False in ultraGridSettings_BeforeHeaderCheckStateChanged event.

 

No problem so far.

But now, when I check a checkbox in the header (it does make the cell values True as expected), and then scroll horizontally using scrollbar, then unexpectedly, the checkmark shifted to the next column’s header checkbox. And carefull noticing, I found that I happens when a column becomes invisible due to scolling. So it is something to do with currently visible columns ? How to resolve this issue ?

 

Another problem:

If I check a header of filtered rows, then remove the filter, still the checkbox is checked. How to Remove the checkmark from the checkbox after the filter is removed ? I have tried using SetHeaderCheckedState method in ultraGridSettings_AfterRowFilterChanged event, but no success.

 

Please let me know the solutions of these issues as soon as possible.

Thanks

 

Dilip

Parents
  • 6158
    Suggested Answer
    Offline posted

    Hello Dilip,

    The behavior of the CheckBox moving to a different column header is very strange and unfortunately,one that I could not reproduce within a sample (which I have attached to this post). Information about whether the CheckBox is displayed, is stored on the ColumnHeader  which is directly associated with an UltraGridColumn. I'm not sure how changes to a column's visibility could affect this, unless the HeaderUIElements are being reused for different columns which I have not see within the code.

    Once I am able to reproduce the behavior, I'll be able to further debug the issue. Please attempt to reproduce it within this sample (making modifications where necessary). Make sure that you are using the latest service release as there has been some fixes to this feature's code base since the initial release of the feature.

     

    As far as your second issue is concerned, what are you passing in as the Rows parameter to the SetHeaderCheckedState() method. The CheckState is stored on the RowsCollection (or Band if null is passed) using the UltraGridColumn as the key into the dictionary. When the HeaderCheckBoxSynchronization is set to Band, it uses the value cached on the Band. Otherwise, it uses the RowsCollection. If the RowsCollection is the not associated with the Header (via its Context), then when the HeaderUIElement retrieves the RowsCollection context, it will be a different RowsCollection and therefore the cached CheckState will not be set.

    My assumption is that null is being passed for the Rows parameter, and therefore the CheckState is being set on the Band. Since the RowsCollection is used when the synchronization is None, you will have to call SetHeaderCheckedState() on the Rows collection for all the parentRow similar to the code below:

                UltraGridBand band = e.Column.Band;

                UltraGridBand parentBand = band.ParentBand;

     

                if (parentBand != null)

                {

                    // in order to set the CheckState for the entire band, we need to call 

                    // SetHeaderCheckedState() for every parent row's Rows collection

                    foreach (UltraGridRow parentRow in parentBand.GetRowEnumerator(GridRowType.DataRow))

                    {

                        RowsCollection rows = parentRow.ChildBands[band].Rows;

                        band.Columns["A"].SetHeaderCheckedState(rows, false);

                        band.Columns["B"].SetHeaderCheckedState(rows, false);

                        band.Columns["C"].SetHeaderCheckedState(rows, false);

                        band.Columns["D"].SetHeaderCheckedState(rows, false);

                    }

                }

                else

                {

                    // root level tables, so we only need to set the CheckState for the grid's Rows collection

                    band.Columns["A"].SetHeaderCheckedState(this.ultraGrid1.Rows, false);

                    band.Columns["B"].SetHeaderCheckedState(this.ultraGrid1.Rows, false);

                    band.Columns["C"].SetHeaderCheckedState(this.ultraGrid1.Rows, false);

                    band.Columns["D"].SetHeaderCheckedState(this.ultraGrid1.Rows, false);

                }

     

     

    Note that they're have been some recent additions to allow the setting of the Header CheckBox to Indeterminate via a new overload to the SetHeaderCheckedState(). This code should be released in the next service release.

    If you require further assistance, please let me know.

    Thanks,

    Chris

     

     

     

Reply Children
No Data