Hi boopalslm,
Please take reference to the below code and correct your code.
HTML
Namespaces
C#
using System.Collections.Generic;
using System.Data;
Code
C#
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.BindDataGrid();
}
private void BindDataGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(string)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add("", "", "");
dt.Rows.Add("1", "John Hammond", "USA");
dt.Rows.Add("2", "Mudassar Khan", "India");
dt.Rows.Add("3", "Suzanne Mathews", "Rusia");
dt.Rows.Add("", "", "");
dataGridView1.DataSource = dt;
}
private void btn_Check(object sender, EventArgs e)
{
List<int> liRow= new List<int>();
bool isRowEmpty = true;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if (!string.IsNullOrEmpty(dataGridView1.Rows[i].Cells[j].Value.ToString()))
{
isRowEmpty = false;
break;
}
else
{
isRowEmpty = true;
}
}
if (isRowEmpty)
{
liRow.Add(i + 1);
}
}
string message = string.Join(",", liRow.ToArray());
MessageBox.Show("row " + message + " is Empty");
}
}
Screenshot