Skip to main content Skip to footer

How to blink cells based on value in C1TrueDBGrid

Blinking Cell Based on Cell Value

This can be easily accomplished using the AddRegexCellStyle method, which lets the user set the cell style based on the contents of the cell. For instance, suppose we want to blink cell when cell value is "Y". Here is the code for the same:

bool bblink = false;  
void timer1_Tick(object sender, EventArgs e)  
{  
  if (bblink)  
  {  
    C1.Win.C1TrueDBGrid.Style S1 = new C1.Win.C1TrueDBGrid.Style();  
    S1.BackColor = Color.Red;  
    this.c1TrueDBGrid1.Splits[0].DisplayColumns[2].AddRegexCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.AllCells, S1, "Y");  
  }  
  else  
  {  
    C1.Win.C1TrueDBGrid.Style S2 = new C1.Win.C1TrueDBGrid.Style();  
    S2.BackColor = Color.White;  
    this.c1TrueDBGrid1.Splits[0].DisplayColumns[2].AddRegexCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.AllCells, S2, "Y");  
  }  
  bblink = !bblink;  
}  

WinForms Datagrid Blink Cells

Blink Cell Based on Value of Different Column in the Table

The FetchCellStyle event is used to set cell styles in a column based on custom criteria. We will use this for our implementation. The FetchStyle property of the column whose cells are to be blinked is set to True. The timer would keep on changing the FetchStyle property to True and False alternatively which fires the FetchCellStyle event. In this event we set and reset the backcolor of the cell to give it a blinking effect. Here is the code that accomplishes the same:

void c1TrueDBGrid2_FetchCellStyle(object sender, C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs e)  
{  
  System.Data.DataRowView dr = (System.Data.DataRowView)this.c1TrueDBGrid2[this.c1TrueDBGrid2.RowBookmark(e.Row)];  
  if ((int)dr[1] <= 300)  
     e.CellStyle.BackColor = Color.Blue;  
}  
void timer2_Tick(object sender, EventArgs e)  
{  
  c1TrueDBGrid2.Splits[0].DisplayColumns[2].FetchStyle = !c1TrueDBGrid2.Splits[0].DisplayColumns[2].FetchStyle;  
}  

WinForms TrueDBGrid Blink Cells