Completed
Last Updated: 27 May 2015 08:22 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 17 Feb 2015 11:20
Category: GridView
Type: Bug Report
0
FIX. RadGridView - wrong cells are selected when the column is partially visible
To reproduce: use the following code snippet and refer to the attached gif file:

public Form1()
{
    InitializeComponent();
    for (int i = 0; i < 20; i++)
    {
        this.radGridView1.Columns.Add("Col" + i);
    }

    for (int i = 0; i < 10; i++)
    {
        GridViewDataRowInfo row = this.radGridView1.Rows.AddNew() as GridViewDataRowInfo;
        foreach (GridViewColumn col in this.radGridView1.Columns)
        {
            row.Cells[col.Name].Value = "Data" + row.Index + "." + col.Index;
        }
    }

    this.radGridView1.MultiSelect = true;
    this.radGridView1.SelectionMode = GridViewSelectionMode.CellSelect;
}


Workaround:
int startColumn = int.MaxValue;
int endColumn = 0;
int startRow = int.MaxValue;
int endRow = 0;

private void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    GridDataCellElement cellElement = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
    if (cellElement != null)
    {
        startColumn = cellElement.ColumnIndex;
        startRow = cellElement.RowIndex;
    }
}

private void radGridView1_MouseUp(object sender, MouseEventArgs e)
{
    GridDataCellElement cellElement = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
    if (cellElement != null)
    {
        endColumn = cellElement.ColumnIndex;
        endRow = cellElement.RowIndex;
    }

    if (endColumn < startColumn)
    {
        int swap = endColumn;
        endColumn = startColumn;
        startColumn = swap;
    }
    if (endRow < startRow)
    {
        int swap = endRow;
        endRow = startRow;
        startRow = swap;
    }

    this.radGridView1.ClearSelection();
    int scrollBarValue = 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.HScrollBar.Value = scrollBarValue;
}
0 comments