开发者

Check which bound DataGridViewColumn is clicked on

The DataGridViewCellMouseEventArgs object provided in the events (eg CellMouseDown, CellDoubleClicked) gives the column as a numeric index in DataGridView.Columns but I don't want to hardcode a number into my event handler. I'm using a strongly typed dataset and am wondering if there's a way 开发者_开发知识库to find out what the column index for MyDataRowType.TheColumnImLookingFor in the DGV is programatically.


You could do the following to get the matching column:

if (dataGridView1.Columns[e.ColumnIndex].DataPropertyName == _myDataSet.DataTable1.DataColumn2Column.ColumnName)
{
    // Do Work 
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜