Category / Section
How to insert animated image to a grid cell in WinForms GridControl?
2 mins read
Inserting an animated image into a grid cell
You can animate the image inside the Grid cell by setting the CellType as Picturebox control, and you can customize the timer to refresh the picture displaying time interval for displaying pictures like an animated one. The following code example explains how to set the cell type and refresh the grid at a proper interval time.
// Creates picture instance.
pb.Image = Image.FromFile(@"..\\..\\Lock.gif");
Timer t = new Timer() { Interval = 50 };
t.Tick += new EventHandler(t_Tick);
t.Start()
void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.ColIndex == 1 && e.RowIndex == 1)
{
// Sets Cell Type.
e.Style.CellType = GridCellTypeName.Control;
// sets image to the cell.
e.Style.Control = pb;
}
}
// Refreshes the grid.
void t_Tick(object sender, EventArgs e)
{
if (gridControl1.CurrentCell != null && !gridControl1.CurrentCell.HasCurrentCellAt(1, 1))
{
gridControl1.RefreshRange(GridRangeInfo.Cell(1, 1));
}
}'Creates picture instance.
pb.Image = Image.FromFile("..\\..\\Lock.gif")
Dim t As New Timer() With {.Interval = 50}
AddHandler t.Tick, AddressOf t_Tick
t.Start() void gridControl1_QueryCellInfo(Object sender, GridQueryCellInfoEventArgs e)
If e.ColIndex = 1 AndAlso e.RowIndex = 1 Then
' Sets Cell Type.
e.Style.CellType = GridCellTypeName.Control
' sets image to the cell.
e.Style.Control = pb
End If
' Refreshes the grid.
void t_Tick(Object sender, EventArgs e)
If gridControl1.CurrentCell IsNot Nothing AndAlso (Not gridControl1.CurrentCell.HasCurrentCellAt(1, 1)) Then
gridControl1.RefreshRange(GridRangeInfo.Cell(1, 1))
End IfThe following
screenshot displays the image loaded and refreshed in a cell.
Samples: