How To Insert Animated Image To A Grid Cell In Winforms Gridcontrol?
animation
cell-type
celltype
grid-cell
gridcontrol
image
winforms
In WinForms GridControl, you can animate the image inside the GridCell 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.
C#
// 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));
}
}
VB.NET
'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 If
Take a moment to peruse the WinForms GridControl Documentation, where you can find about gridcontrol with code examples.