DataGridView.CellClick方法不起作用 [英] DataGridView.CellClick method doesn't work

查看:475
本文介绍了DataGridView.CellClick方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我在表单上有两个datagridviews(dgv)。我从第一个dgv(dgvTable)中选择dataID,并在其他dgv中获取这些id的所有值。
但e方法dgvTable.CellClick()没有任何效果。我得到了emtpy dgv。
请帮助

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

推荐答案

在您的评论后,我建议您使用 .ToList( )帮助网格识别数据源:

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;

这篇关于DataGridView.CellClick方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆