参考下下面的代码: DataGridViewRow row = (sender as DataGridView).Rows[e.RowIndex]; DataRow dr = row.DataBoundItem as DataRow; if (dr == null) { DataRowView dv = row.DataBoundItem as DataRowView; if (dv != null) { dr = dv.Row; } }
粘全了吧: private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { DataGridViewRow row = (sender as DataGridView).Rows[e.RowIndex]; DataRow dr = row.DataBoundItem as DataRow; if (dr == null) { DataRowView dv = row.DataBoundItem as DataRowView; if (dv != null) { dr = dv.Row; } } }
DataGridViewRow row = (sender as DataGridView).Rows[e.RowIndex];
DataRow dr = row.DataBoundItem as DataRow;
if (dr == null)
{
DataRowView dv = row.DataBoundItem as DataRowView;
if (dv != null)
{
dr = dv.Row;
}
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewRow row = (sender as DataGridView).Rows[e.RowIndex];
DataRow dr = row.DataBoundItem as DataRow;
if (dr == null)
{
DataRowView dv = row.DataBoundItem as DataRowView;
if (dv != null)
{
dr = dv.Row;
}
}
}