button to loop on selected rows with btnnext and btnprev buttons

2 posts, 0 answers
  1. Imo
    Imo avatar
    4 posts
    Member since:
    Sep 2012

    Posted 03 Oct 2011 Link to this post

    hi everybody is there a way that we could loop to selected rows using two buttons button1 and button2, like for example i want the small arrow to point to the first selected row with document name f10_oct1_en.pdf, currently it is pointing to f36_may07_en.pdf, and each time i click the button it jumps to the next selected row which in my case if the arrow is on f10_oct1_en.pdf will go to f21_dec17_en.pdf, same thing will happen to the prev button only going backwards..
    i have attached a png file on the thread so you could understand what i mean...
    thank you very much...
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 05 Oct 2011 Link to this post

    Hello Imo,

    There is no clean way to do this, but this method should do what you need:
    For this to work you need .net 3.5 and add using System.Linq...

    private void MoveToSelectedRow(bool next)
        if (_radGridView.CurrentRow == null)
        if (_radGridView.SelectedRows.Count <= 1) return;
        var index = _radGridView.Rows.IndexOf(_radGridView.CurrentRow);
        var rows =
                r => (next ? r.Index > index : r.Index < index) && _radGridView.SelectedRows.Contains(r));
        var rowToSelect = next ? rows.FirstOrDefault() : rows.LastOrDefault();
        if (rowToSelect == null)
            rowToSelect = next
                              ? _radGridView.Rows.Where(r => _radGridView.SelectedRows.Contains(r)).FirstOrDefault()
                              : _radGridView.Rows.Where(r => _radGridView.SelectedRows.Contains(r)).LastOrDefault();
        var selectedRows = _radGridView.SelectedRows.ToArray();
        _radGridView.CurrentRow = rowToSelect;
        foreach (var row in selectedRows)
            row.IsSelected = true;

    I know it's not that clean, but it will do what you need.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
Back to Top