加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何判断是否至少选择了一个dataGridView行c#

发布时间:2020-12-16 01:51:38 所属栏目:百科 来源:网络整理
导读:我有一个程序从dataGridView中的选定行获取值并将其传递给函数.但是,gridView可能为空或无法选择行. 我处理了空网格,但我想知道是否有办法,如果我可以判断是否选择了任何行. 我试过这个: if (Convert.ToInt32(dataGridView1.Rows.Count) 0){ //It is not em
我有一个程序从dataGridView中的选定行获取值并将其传递给函数.但是,gridView可能为空或无法选择行.
我处理了空网格,但我想知道是否有办法,如果我可以判断是否选择了任何行.

我试过这个:

if (Convert.ToInt32(dataGridView1.Rows.Count) > 0)
{
    //It is not empty
}
int c = dataGridView1.SelectedRows.Count(); //this line gives me an error
if (c>0)
{
    //there is a row selected
}

你知道我怎么解决这个问题?

解决方法

您只需删除“Count”关键字后的括号即可.它应该如下所示:

if (Convert.ToInt32(dataGridView1.Rows.Count) > 0)
{
    //It is not empty
}
int c = dataGridView1.SelectedRows.Count; //remove parenthesis here
if (c>0)
{
    //there is a row selected
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读