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

How to select a cell

1 Answer 16 Views
GridView
This is a migrated thread and some comments may be shown as answers.
alli
Top achievements
Rank 1
alli asked on 19 Jul 2017, 01:51 PM
How to get a cell number by clicking on the row

1 Answer, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 24 Jul 2017, 01:22 PM
Hello ,

Thank you for contacting us.

I am not exactly sure what you mean by cell number. If you want to get the current click cell when a row is selected you can subscribe to the SelectedCellsChanged event of the RadGridView and use the CurrentCell property of the grid. This property represents the current cell.
private void RadGridView_SelectedCellsChanged(object sender, Telerik.Windows.Controls.GridView.GridViewSelectedCellsChangedEventArgs e)
{
    var gridView = sender as RadGridView;
    var selectedCell = gridView.CurrentCell as GridViewCell;
}

If by cell number you mean the row and column index you can get the column index from the DisplayIndex property of the column of the cell. As for the row index, you can use the ContainerFromItem and IndexFromContainer methods of the ItemContainerGenerator property of the RadGridView. Check the following code snippet.
private void RadGridView_SelectedCellsChanged(object sender, Telerik.Windows.Controls.GridView.GridViewSelectedCellsChangedEventArgs e)
{
    var gridView = sender as RadGridView;
    var cell = e.AddedCells[0] as GridViewCellInfo;
 
    var selectedCell = gridView.CurrentCell as GridViewCell;
    var container = gridView.ItemContainerGenerator.ContainerFromItem(cell.Item);
 
    var columnIndex = selectedCell.Column.DisplayIndex;
    var rowIndex = gridView.ItemContainerGenerator.IndexFromContainer(container);
}

Hope this information is helpful.

Regards,
Dinko
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
alli
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Share this question
or