int i = 0; foreach (DataRow row in Products.Tables["Products"].Rows) { string value = row["test"].ToString(); string newVal = value.Trim(); if (value == null) { i += 1; } } if (i == 0) { ProductDataGrid.Columns["test"].Visible = false; MessageBox.Show("test successfully hidden"); }