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
435
Selecting rows using a checkbox
posted

I know that there are a few posts on this subject on this forum, but nothing exactly as what I'm after - so here goes....

I'm using a Grid where the user can select a number of rows from it. The standard functionality (i.e. CTRL-select, SHIFT-select) is going to be too complex for them - they are after a simple checkbox column which will highlight the selected columns. Ideally I'd like to have a checkbox in the column header so that they could toggle the lot of them on and off easily, but this isn't essential - I can just make a standard checkbox with a "Toggle" label next to the Grid instead.

I guess what I'm asking is:

1. Is there built in functionality to do this sort of selection (I couldn't find anything so far)?

2. If I want to do this and it's not built in, can I just make an unbound column which will be the selector column?

3. I would - ideally - want the checkbox to "select" the rows in the Grid so that I can do the in-built grid functions to get all selected rows etc. - but then I'll need to prevent users selecting rows in the conventional way (ctrl, shift clicking etc.). Does this sound feasible or would it just be easier to stick with checkboxes and manually iterate through the rows to find out which have the checkbox checked?

Thanks in advance

Isaac

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Isaac,

        Are you talking about selecting rows or columns? You seem to jump back and forth a couple of times in your post so I am a bit confused.

        You seem to be talking mostly about rows, so I will answer your questions under the assumption that we are discussing selecting rows.

        1) No, there's nothing like this built-in to the grid.

        2) Yes, you could add an Unbound checkbox column to your grid. You would probably do this in the InitializeLayout event of the grid. You just add the column, set the DataType to Boolean, and maybe apply a CellAppearance to the column to make it look like a header of some sort or whatever you want.  

        3) No, this won't work. You could handle the CellChange event of the grid and select the row when the checkbox is checked, but the selection will be lost as soon as the user clicks on another cell.

        What I would do is keep my own internal list of rows. You can use a List<UltraGridRow> and add and remove items from the list whenever they are checked or unchecked. You would use the CellChange event for this. Be sure to use the Text property of the cell when inside this event - Value will not be updated untli later.

        Then what you do is use the InitializeRow event of the grid and each time it fires, you check the Value of the CheckBox cell and apply an appearance to the row to make it appear selected.

Reply Children