Recently, one of our customer using C1TrueDBGrid came up with an interesting requirement where in the customer wanted to display a blinking cell in TrueDBGrid. Blinking a cell can be accomplished by changing the backcolor of the cell based on a timer. Here in this blog, lets discuss two different approaches for blinking cell :
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;
}
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;
}
Please refer to the attached samples for complete implementation. Download C# Sample Download VB Sample