开发者

How to get CurrentCell location in DataGridView

开发者 https://www.devze.com 2023-01-27 12:07 出处:网络
HI How to get CurrentCell location in Data开发者_开发知识库GridView. 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?You

HI How to get CurrentCell location in Data开发者_开发知识库GridView. 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号