Multiselect for the radgridview

9 posts, 1 answers
  1. tony
    tony avatar
    12 posts
    Member since:
    Nov 2014

    Posted 04 Mar 2015 Link to this post

    Hi everyone,
    I meet a trouble that I can't multiselect all cells by mouse drag when we create a big table.

    My version is 2014.1.402.20, I use radgridview.
    e.g.
    1. I create 10 by 10 cells table and gridview is a small one, it will show horizon scroll bar and vertical scroll bar.
    2. I want to select all cells by mouse drag but not CTRL+Click.
    3. I can't select all of them.

    Please review my attachment. Thanks.
  2. tony
    tony avatar
    12 posts
    Member since:
    Nov 2014

    Posted 04 Mar 2015 Link to this post

    Hello ervery,
    My code:
    this.radGridView1.SelectionMode = GridViewSelectionMode.CellSelect;
    this.radGridView1.MasterTemplate.MultiSelect = true;
    this.radGridView1.MasterTemplate.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect;
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 06 Mar 2015 Link to this post

    Hello Tony,

    Thank you for writing.

    This is a known issue with RadGridView multiple selection. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item. You can have a look at the introduced workaround in the referred item.

    I hope this information helps. Should you have further questions, I would be glad to help.
     
    Regards,
    Dess
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. tony
    tony avatar
    12 posts
    Member since:
    Nov 2014

    Posted 26 Mar 2015 in reply to Dess Link to this post

    Sorry, It still has this issue. :(
  6. tony
    tony avatar
    12 posts
    Member since:
    Nov 2014

    Posted 26 Mar 2015 in reply to Dess Link to this post

    Sorry, It still has this issue.
  7. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 30 Mar 2015 Link to this post

    Hello Tony,

    Thank you for writing back.

    I confirm that when you select a cell and drag the selection first horizontally and then vertically, there are missing selected cells. This case can be handled with the RadGridView.MouseUp event. Here is a sample implementation which should be used together with the already applied workaround:
    private void radGridView1_MouseUp(object sender, MouseEventArgs e)
    {
        int startColumn = this.radGridView1.Columns.Last().Index;
        int endColumn = 0;
        int startRow = this.radGridView1.Rows.Last().Index;
        int endRow = 0;
     
        for (int i = 0; i < this.radGridView1.SelectedCells.Count; i++)
        {
            if (this.radGridView1.SelectedCells[i].ColumnInfo.Index < startColumn)
            {
                startColumn = this.radGridView1.SelectedCells[i].ColumnInfo.Index;
            }
            else if (this.radGridView1.SelectedCells[i].ColumnInfo.Index > endColumn)
            {
                endColumn = this.radGridView1.SelectedCells[i].ColumnInfo.Index;
            }
     
            if (this.radGridView1.SelectedCells[i].RowInfo.Index < startRow &&
                this.radGridView1.SelectedCells[i].RowInfo.Index > -1)
            {
                startRow = this.radGridView1.SelectedCells[i].RowInfo.Index;
            }
            else if (this.radGridView1.SelectedCells[i].RowInfo.Index > endRow)
            {
                endRow = this.radGridView1.SelectedCells[i].RowInfo.Index;
            }
        }
     
        int scrollBarValue = this.radGridView1.TableElement.VScrollBar.Value;
        this.radGridView1.BeginUpdate();
        for (int i = startRow; i < endRow + 1; i++)
        {
            for (int j = startColumn; j < endColumn + 1; j++)
            {
                if (!this.radGridView1.Rows[i].Cells[j].IsSelected)
                {
                    this.radGridView1.Rows[i].Cells[j].IsSelected = true;
                }
            }
        }
        this.radGridView1.EndUpdate();
        this.radGridView1.TableElement.VScrollBar.Value = scrollBarValue;
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  8. tony
    tony avatar
    12 posts
    Member since:
    Nov 2014

    Posted 03 Apr 2015 in reply to Dess Link to this post

    Thanks for your reply.
    I have another question.
    I can't smooth scroll bar to the end after I use your code.
    The position of scroll bar will change to start position automatically.
    Shall we support 2 selection mode?
    1. press ctrl + mouse click to select any cells.
    2. drag mouse to select cells what we want.

    Thanks.
  9. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 07 Apr 2015 Link to this post

    Hello Tony,

    Thank you for writing back.

    It seems that the smooth scrolling is not affected on my end with the specified version 2014.1.402.40. Please refer to the attached gif file illustrating the behavior on my end after implementing the suggested solution.  

    However, the horizontal scroll-bar is indeed reset to its left most position which can be avoided with manually storing the horizontal scroll-bar value:
    private void radGridView1_MouseUp(object sender, MouseEventArgs e)
    {
        int startColumn = this.radGridView1.Columns.Last().Index;
        int endColumn = 0;
        int startRow = this.radGridView1.Rows.Last().Index;
        int endRow = 0;
     
        for (int i = 0; i < this.radGridView1.SelectedCells.Count; i++)
        {
            if (this.radGridView1.SelectedCells[i].ColumnInfo.Index < startColumn)
            {
                startColumn = this.radGridView1.SelectedCells[i].ColumnInfo.Index;
            }
            else if (this.radGridView1.SelectedCells[i].ColumnInfo.Index > endColumn)
            {
                endColumn = this.radGridView1.SelectedCells[i].ColumnInfo.Index;
            }
     
            if (this.radGridView1.SelectedCells[i].RowInfo.Index < startRow &&
                this.radGridView1.SelectedCells[i].RowInfo.Index > -1)
            {
                startRow = this.radGridView1.SelectedCells[i].RowInfo.Index;
            }
            else if (this.radGridView1.SelectedCells[i].RowInfo.Index > endRow)
            {
                endRow = this.radGridView1.SelectedCells[i].RowInfo.Index;
            }
        }
     
        int vScrollBarValue = this.radGridView1.TableElement.VScrollBar.Value;
        int hScrollBarValue = this.radGridView1.TableElement.HScrollBar.Value;
        this.radGridView1.BeginUpdate();
        for (int i = startRow; i < endRow + 1; i++)
        {
            for (int j = startColumn; j < endColumn + 1; j++)
            {
                if (!this.radGridView1.Rows[i].Cells[j].IsSelected)
                {
                    this.radGridView1.Rows[i].Cells[j].IsSelected = true;
                }
            }
        }
        this.radGridView1.EndUpdate();
        this.radGridView1.TableElement.VScrollBar.Value = vScrollBarValue;
        this.radGridView1.TableElement.HScrollBar.Value = hScrollBarValue;
    }

    As to the question about selecting cells by using the Ctrl key and cell selection, you should modify a little bit the MouseUp event handler in order not to perform the range selection in this case:
    private void radGridView1_MouseUp(object sender, MouseEventArgs e)
    {
        if(ModifierKeys == Keys.Control)
        {
            return;
        }
     
    //...
     
    }

    I hope this information helps. If you have any additional questions, please let me know.
     
    Regards,
    Dess
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  10. tony
    tony avatar
    12 posts
    Member since:
    Nov 2014

    Posted 17 Apr 2015 in reply to Dess Link to this post

    Thanks you very much! :)
Back to Top
UI for WinForms is Visual Studio 2017 Ready