Home Forums WPF controls Xceed DataGrid for WPF Selecting Rows programmatically (Extended selection mode)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22489 |

    Hi,

    I’m trying to implement a Ctrl-A handler in the data grid that selects all rows. Below is my attempt at selecting only the first two rows, but the method [Row.SetIsSelected()] I am trying to use is marked internal…

    private void Select2FirstRows()
    {
    // init
    thegrid.SelectedItems.Clear();
    thegrid.CurrentColumn = thegrid.Columns[0];
    thegrid.CurrentItem = thegrid.Items[0];

    // select row 0
    dg.DataRow row = thegrid.ItemContainerGenerator.ContainerFromItem(thegrid.CurrentItem) as dg.DataRow;
    // next statement does not compile; method SetIsSeleced is internal
    row.SetIsSelected(true);

    }

    Is there a better way?

    I would also want to implement Ctrl-Shift-Down [select all rows from current row to the bottom] etc. I have already implemented a Delete routine that removes all selected rows; so its just a matter of getting the selection to work.

    Friedrich

    Imported from legacy forums. Posted by Friedrich (had 5021 views)

    Xceed Support
    Member
    Post count: 5658

    The SelectedItems, SelectedItems and SelectedIndex properties can be assigned “data objects” to allow selection of the items.

    The DataRow statuses will be updated accordingly when those properties are set.

    instead of:
    <code>
    // select row 0
    dg.DataRow row = thegrid.ItemContainerGenerator.ContainerFromItem(thegrid.CurrentItem) as dg.DataRow;
    // next statement does not compile; method SetIsSeleced is internal
    row.SetIsSelected(true);
    </code>

    you can do:

    <code>
    thegrid.SelectedItems.Add(thegrid.Items[0]);
    </code>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 427 views)

    Odi [Xceed]
    Spectator
    Post count: 426

    >>Is there a better way?

    Perhaps this could be offered in a built-in way so can just turn on some property and presto, Control-A, Ctrl-Shift-Down, and certain other (sometimes expected) key handling behaviors like those are enabled, and you don’t have to code anything.

    …I’ve added it to the feature requests database for consideration.

    Odi

    Imported from legacy forums. Posted by Odi [Xceed] (had 392 views)

    User (Old forums)
    Member
    Post count: 23064

    Just wanted to let you know how I appreciate your thoughtful and prompt replies. I will try the proposed approach.

    F.

    Imported from legacy forums. Posted by Friedrich (had 601 views)

    User (Old forums)
    Member
    Post count: 23064

    Marc,

    your approach sort-of works – the rows do get selected, but the only visual that this is happening is that the text colour turns to gray. Deleting the selected rows does work, but what I really would like is to have visual feedback to the user – the same that he or she would get by typing shift-down to select the row manually.

    Another question about selection: It would seem intutive for the user to be able to select rows by dragging on the rowselector (to the left of the grid). Is there an easy way to get this behavior? If not, can you point me to the harder solution?

    thanks,

    Friedrich

    Imported from legacy forums. Posted by Friedrich (had 1000 views)

    User (Old forums)
    Member
    Post count: 23064

    We have added support for the selectAll command, you can obtain this fix in the latest package available <a href=”http://xceed.com/pages/TopMenu/Downloads/Trials.aspx”>here </a>

    Imported from legacy forums. Posted by Matt (had 5058 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.