Hi raiamit,
After trying a lot i conclude that it is not possible without timer. Here i have created a sample as per your need.
Please refer the below code. Here i have checked with country Finland. So you need to change as per your condition.
C#
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
BindGrid();
}
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
timer1.Start();
Thread thread = new Thread(Blink);
thread.Start();
}
bool go = false;
int count = 100;
private void Blink(object o)
{
while (count > 0)
{
while (!go)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[2].Value.ToString().ToUpper() == "FINLAND")
{
row.DefaultCellStyle.BackColor = Color.Red;
}
}
go = true;
Thread.Sleep(500);
}
while (go)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[2].Value.ToString().ToUpper() == "FINLAND")
{
row.DefaultCellStyle.BackColor = Color.Green;
}
}
go = false;
Thread.Sleep(500);
}
}
}
private void BindGrid()
{
string constring = @"Data Source=.;Initial Catalog=Northwind;User id = sa;password = sa";
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 * FROM Customers", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
//Set AutoGenerateColumns False
dataGridView1.AutoGenerateColumns = false;
//Set Columns Count
dataGridView1.ColumnCount = 3;
//Add Columns
dataGridView1.Columns[0].Name = "CustomerId";
dataGridView1.Columns[0].HeaderText = "Customer Id";
dataGridView1.Columns[0].DataPropertyName = "CustomerID";
dataGridView1.Columns[1].HeaderText = "Contact Name";
dataGridView1.Columns[1].Name = "Name";
dataGridView1.Columns[1].DataPropertyName = "ContactName";
dataGridView1.Columns[2].Name = "Country";
dataGridView1.Columns[2].HeaderText = "Country";
dataGridView1.Columns[2].DataPropertyName = "Country";
dataGridView1.DataSource = ds.Tables[0];
}
}
}
}
}
}
Screenshot
