DataGridView.CellClick method doesn't work

空扰寡人 提交于 2019-12-11 01:39:13

问题


//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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!