Question

HI How to get CurrentCell location in DataGridView. i need for when my load will load every comboboxes set above on datagridview current cell. and get same size. how can i do that?

Was it helpful?

Solution

You can get the zero-based index of the column that contains the currently selected cell by using the ColumnIndex property of the CurrentCell property:

if (myDataGridView.CurrentCell != null)
{
    int columnIndex = myDataGridView.CurrentCell.ColumnIndex;
}

Or, you can get the column object itself that contains the currently selected cell by using the OwningColumn property:

if (myDataGridView.CurrentCell != null)
{
    DataGridViewColumn columnObject = myDataGridView.CurrentCell.OwningColumn;
}

Note that I'm still not entirely sure if this is what you're asking for. My forms don't have columns, so I'm assuming that you mean the DataGridView. And your answer still doesn't really explain what exactly you mean by "location," but this should tell you everything you need to know about the column that contains the current cell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top