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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Feb 9, 2015, 10:46 AM
IsraelPosted Feb 9, 2015, 12:07 PM
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.
IsraelPosted Feb 9, 2015, 8:32 AM
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();
VulpesPosted Feb 6, 2015, 3:03 PM
Note that this code doesn't count the row at the bottom of the grid for adding new records.
Burak SeyhanPosted Feb 6, 2015, 9:43 AM