问题
//FormLoad
dgvTable.CellClick += new DataGridViewCellEventHandler(getValues);
//somwhere in FormClass
private void getValues(object sender, DataGridViewCellEventArgs e)
{
int id = int.Parse(dgvTable.Rows[dgvTable.CurrentRow.Index].Cells[0].Value.ToString());
var values = from c in v.db.TotalDoc
where c.TotalID == id
select c.TotalAmount;
dgvValues.DataSource = values;
}
i have two datagridviews (dgv) on the form. I choose dataID from first dgv (dgvTable) and get all values of these id in the other dgv. but e method dgvTable.CellClick() have no effect. i'm getting emtpy dgv. please help
回答1:
Ok after your comment i just recommend that you use .ToList()
to help grid to recognise the data source :
int id = int.Parse(dgvTable.Rows[dgvTable.CurrentRow.Index].Cells[0].Value.ToString());
var values = (from c in v.db.TotalDoc
where c.TotalID == id
select c.TotalAmount).ToList();
dgvValues.DataSource = values;
来源:https://stackoverflow.com/questions/10033609/datagridview-cellclick-method-doesnt-work