C# DataGridView Check if empty

后端 未结 7 1844
故里飘歌
故里飘歌 2020-12-17 15:01

I have a datagridview which gets filled with data returned from a linq query. If the query returns no results I want to display a messagebox. Is there a way of checking to s

7条回答
  •  遥遥无期
    2020-12-17 15:29

    The DGV.Rows.Count method of checking if DGV is empty does not work if the option AllowUserToAddRows is set to true.

    You have to disable AllowUserToAddRows = false then check for empty like this:

    if (dataGridView1.Rows != null && dataGridView1.Rows.Count != 0)
    

提交回复
热议问题