Category / Section
How to insert animated image to a grid cell in WinForms GridControl?
2 mins read
Inserting an animated image to 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 animated one. The following code example explains how to set cell type and refreshing the grid in a proper interval time.
C#
// Creates picture instance. pb.Image = Image.FromFile(@"..\\..\\Camera_4.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)); } }
VB
' Creates picture instance. pb.Image = Image.FromFile("..\\..\\Camera_4.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 If
The following screenshot displays the image loaded and refreshed in a cell.
Samples:
C#: AnimatedImage-C#
VB: AnimatedImage-VB