Hello!
lblTotal.Text = dvgTest.RowCount.ToString();
With this code I wrote I can easly count all the datagrid row. But I am in need to count only blank row of my datagrid. How can I proceed.
Thanx,
Israel.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 9, 2015, 5:46 AM EST
IsraelRank #1,223 · 1.5K reputationPosted Feb 9, 2015, 7:07 AM EST
your codes are always short, simple, faster, instructive and powerfull.
Your have a very good understanding in C# plateforme.
Need to write codes as you one day to help new futurs C# developer in this site and anywhere.
Thanx and no more comment,
Israel.
Burak SeyhanRank #7,540 · 239 reputationPosted Feb 6, 2015, 4:43 AM EST
VulpesRank #55 · 29.2K reputationPosted Feb 6, 2015, 10:03 AM EST
Note that this code doesn't count the row at the bottom of the grid for adding new records.
IsraelRank #1,223 · 1.5K reputationPosted Feb 9, 2015, 3:32 AM EST
Thanx for your kind codes. But could you tell me just with your this codes how can I read blanks rows for a specific column name?
Firstlty my filter:
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from 1 where (date between ? and ?) and name = ?";
var param1 = new OleDbParameter("@StartDate", OleDbType.Date);
var param2 = new OleDbParameter("@EndDate", OleDbType.Date);
var param3 = new OleDbParameter("@name", OleDbType.VarChar); // use actual type of 'name' here
param1.Value = dataInicialConsPorNomes.Value.Date;
param2.Value = dataFinalConsPorNomes.Value.Date;
param3.Value = txtConsFaltasPorNome.Text; // or whatever
if (dataInicialConsPorNomes.Value <= dataFinalConsPorNomes.Value)
{
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
}
else
{
cmd.Parameters.Add(param2);
cmd.Parameters.Add(param1);
}
cmd.Parameters.Add(param3);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
conn.Close();
dgvPorNomes.DataSource = dt;
Secondly:
after to make a specific filter to count the blank space of this column's name "early":
int count = 0;
foreach (DataGridViewRow row in dvgTest.Rows)
{
if (row.IsNewRow) break;
bool rowIsEmpty = true;
foreach (DataGridViewCell cell in row.Cells)
{
object value = cell.Value;
if (value != null && !Convert.IsDBNull(value) && value.ToString().Trim().Length > 0)
{
rowIsEmpty = false;
break;
}
}
if (rowIsEmpty) count++;
}
lblTotal.Text = count.ToString();