Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current cell column index in DataGridView CurrentCellChanged Event

I have the CurrentCellChanged event handler of a DataGridView and i want to be able to access the current selected cells column index from the event handler.

I used to have the code in the CellClick handler which has DataGridViewCellEventArgs as a parameter so i was able to get the column index from the event args parameter but the CurrentCellChanged event has EventArgs as parameters which i believe is supposed to imply that theres no data for this event.

Is there a way to access the new currently selected cells column index?

like image 241
MBU Avatar asked Apr 21 '11 21:04

MBU


1 Answers

Use DataGridView.CurrentCell property ..

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcell.aspx

int columnIndex = dataGridView.CurrentCell.ColumnIndex;
int rowIndex = dataGridView.CurrentCell.RowIndex;

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.aspx

like image 142
Akram Shahda Avatar answered Sep 28 '22 06:09

Akram Shahda