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
15
WebHierarchicalDataGrid Concern with UnboundCheckBoxField Checked Status in Bands
posted

Hello,

I am having some issues with a column in my band that is set as a UnboundCheckBoxField. The design is for users to select (check) desired rows that they wish to use. This can be as small as 1 row, or all rows generated if necessary. From here they press save and the code behind iterates each row looking for the checked property to be true. All processes after this, when a selected row is found, function as desired.

The problem I am facing is occurring right after the button is clicked. If at least 1 row is selected there seems to be a random chance that before the code behind for the click event even fires every row that was generated in the band is now checked (E.g. Of 56 rows, 1 is selected. Before the first line of the click event is read all 56 checkboxes are checked).

This of course runs the chance of every generated row being saved when a user only wanted 1 or 2. As now the iteration is processing every row.

There is a HeaderCheckBoxMode="Off" property included as well in the column to allow users to easily select all rows if they so choose. Removing this property however seems to fix the concern but if a user requires all rows it would be best to leave this feature in place as well. We have been working with WebDataGrids with check-boxes as well and find no issues using them there. This problem occurs only within WebHierarchicalDataGrid and a Band.

Wondering if this is a known concern or there is a workaround that secures the checked properties?

<Bands>
                <ig:Band Key="ChildBand_0" AutoGenerateColumns="False" DataKeyFields="prj_code,Phase,Task"
                DataMember="PhaseTask" >
                    <Columns>
                            <ig:UnboundCheckBoxField Key="Select" HeaderCheckBoxMode="Off" >
                                     <Header Text="Select">
                                     </Header>
                             </ig:UnboundCheckBoxField>
                              ...
                                                    
                     </Columns>
                    <Behaviors>
                    ...
                   </Behaviors>
                   </Band>
 </Bands>

  • 6325
    Offline posted

    Hello Sheila,

    Thank you for the detailed description you have provided of the issue.

    The desired behavior you have described would be strongly dependent on the exact settings you have used for the WebHierarchicalDataGrid.
    Presuming your "Save" button uses a server-side handler, you can iterate all child rows for a specific row and get the value for their "Select" cells by using the following code-snippet:

    // Child rows of the first parent row.
    var firstRowChildren = hierDataGrid.GridView.Rows[0].RowIslands[0].Rows;
    string checkedChildren = string.Empty;
    
    // Iterate child rows.
    foreach (var childRow in firstRowChildren)
    {
       // Get the checkbox value of the current child row.
        var selectValue = (childRow as GridRecord).Items[4].Value; // 4th item is the cell of 'Select' column.
        if (selectValue is bool && ((bool)selectValue))
        {
            // If the checkbox value is true, append the value from the "Description" cell of the child row to our string.
            // Here you can populate a collection of your choice with the checked child rows.
            checkedChildren += (childRow as GridRecord).Items[1].Value + "<br/>"; // 1st item is the cell of 'Description' column.
        }
        label.Text = checkedChildren;            
    }


    I have attached a sample application that demonstrates the approach from above by following the code-snippet you have provided. In order to test it, you can expand the first parent row and start checking/unchecking the checkboxes for the child rows. After that by clicking the "Click" button, we can see information for the currently checked child rows.
    (Please note that you might have to change the assembly references and the stylesSetPath property in the Web.config so they target your specific version and path for the styles.)

    If you have any questions, please let me know.

    0435.WebHierarchicalDataGrid_sample.zip