This is a migrated thread and some comments may be shown as answers.

Prevent selection of cells

1 Answer 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 22 Jul 2010, 01:25 PM
Hello,

i have implemented a method that prevent the selections of cells in the first 3 columns. this method works, but it is extreme slowly. This is my method. Is there a better way to prevent selection?
private void Event_SelectionChanged(object sender, EventArgs e)
 {
       GridViewCellInfo[] cells = (from GridViewCellInfo entry in
           this.SelectedCells where entry.ColumnInfo.Index <
           CurveContentGridView.FIRST_DATACOLUMN_INDEX ||
           entry.RowInfo.Index == -1
            select entry).ToArray();
 
        for (int i = 0; i < cells.Length; i++)
        {
             cells[i].IsSelected = false;
        }   
}

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 26 Jul 2010, 05:25 PM
Hi Thomas,

When you change the IsSelected property of GridViewCellInfo instances you cause SelectionChanged event to be fired. Therefore, the logic that is inside the event handler is executed again. You can create a boolean field which will be updated when you are clearing the cells that you do not want to be selected. You can use the following code snippet:
private bool resetSelection = false;
 
private void radGridView2_SelectionChanged(object sender, EventArgs e)
{
    if (resetSelection)
    {
        return;
    }
 
    GridViewCellInfo[] cells = (from GridViewCellInfo entry in
                                    this.radGridView2.SelectedCells
                                where entry.ColumnInfo.Index <
                                    FIRST_DATACOLUMN_INDEX ||
                                    entry.RowInfo.Index == -1
                                select entry).ToArray();
 
    resetSelection = true;
    for (int i = 0; i < cells.Length; i++)
    {
        cells[i].IsSelected = false;
    }
    resetSelection = false;
}

Best wishes,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or