Hello,
I have changed the backcolor of the rows based on condition, also i have to count the number of rows for the same condition. kindly help me.
this is my code,
try
{
if (e.ColumnIndex == this.dataGridView1.Columns["POST"].Index)
{
string RepVisits = e.Value.ToString();
if (RepVisits != null)
{
if (RepVisits == "M")
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightPink;
}
else if (RepVisits == "P")
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightBlue;
}
else if (RepVisits == "S")
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGreen;
}
else if (RepVisits == "F")
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightCyan;
}
else
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
}
}
}
}
catch
{
}
Loading
Khargesh RajputPosted Apr 23, 2015, 2:41 AM
int intM=0;
int intP=0;
int intS=0;
suppose your Post column is on cell 1 index
foreach(DataGridViewRow row in DataGridView1.Rows)
{
if(row.Cells[1].Value.ToString().Equals("M"))
{
intM++;
}
else if(row.Cells[1].Value.ToString().Equals("P"))
{
intP++;
}
else if(row.Cells[1].Value.ToString().Equals("S"))
{
intS++;
}
}
Now Show Count values on label
praveen kumarPosted Apr 23, 2015, 2:24 AM
Thank you
Khargesh RajputPosted Apr 23, 2015, 2:15 AM
and count
intcountM=0;
intcountP=0;
as
if( if (RepVisits == "M")
{
intcountM++;
}
if( if (RepVisits == "P")
{
intcountP++;
}
vise versa Inside Foreach loop