How to set an image as a background for a cell in WinForms GridGroupingControl?
Set image as Background for a cell
The following methods are used to set an image as a background for the cell in WinForms GridGroupingControl,
1. By using DrawCell event
2. By using QueryCellStyleInfo event
3. By using GridColumnDescriptor
The following code examples explain how to set an image as a background for the cell by using DrawCell event.
C#
// Event hooking this.gridGroupingControl1.TableControl.DrawCell += TableControl_DrawCell; void TableControl_DrawCell(object sender, GridDrawCellEventArgs e) { ImageList image = new ImageList(); e.Style.TextColor = Color.Red; e.Style.BackgroundImage = System.Drawing.Image.FromFile(@"..\..\Note.jpg"); }
VB
' Event hooking Private Me.gridGroupingControl1.TableControl.DrawCell += AddressOf TableControl_DrawCell Private Sub TableControl_DrawCell(ByVal sender As Object, ByVal e As GridDrawCellEventArgs) Dim image As New ImageList() e.Style.TextColor = Color.Red e.Style.BackgroundImage = System.Drawing.Image.FromFile("..\..\Note.jpg") End Sub
Screenshot
The following code examples explain how to set an image as a background for cell by using QueryCellStyleInfo event.
C#
// Event hooking this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo; void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) { if(e.TableCellIdentity.ColIndex == 3 && e.TableCellIdentity.RowIndex == 4) { Bitmap b = new Bitmap(@"..\..\Note.jpg"); e.Style.TextColor = Color.Red; e.Style.BackgroundImage = b; } }
VB
' Event hooking Private Me.gridGroupingControl1.QueryCellStyleInfo += AddressOf gridGroupingControl1_QueryCellStyleInfo Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs) If e.TableCellIdentity.ColIndex = 3 AndAlso e.TableCellIdentity.RowIndex = 4 Then Dim b As New Bitmap("..\..\Note.jpg") e.Style.TextColor = Color.Red e.Style.BackgroundImage = b End If End Sub
Screenshot
The following code examples explain how to set an image as a background for the cell by using GridColumnDescriptor property.
C#
GridColumnDescriptor columnDescriptor = this.gridGroupingControl1.TableDescriptor.Columns["CLM3"]; columnDescriptor.Appearance.ColumnHeaderCell.CellType = GridCellTypeName.Static; columnDescriptor.HeaderText = "text"; columnDescriptor.Appearance.ColumnHeaderCell.TextColor = Color.Red; // Draws image for a particular column. columnDescriptor.Appearance.ColumnHeaderCell.BackgroundImage = System.Drawing.Image.FromFile(@"..\..\Note.jpg"); columnDescriptor.Appearance.ColumnHeaderCell.BackgroundImageMode = GridBackgroundImageMode.CenterImage;
VB
Dim columnDescriptor As GridColumnDescriptor = Me.gridGroupingControl1.TableDescriptor.Columns("CLM3") columnDescriptor.Appearance.ColumnHeaderCell.CellType = GridCellTypeName.Static columnDescriptor.HeaderText = "text" columnDescriptor.Appearance.ColumnHeaderCell.TextColor = Color.Red; ' Draws image for a particular column. columnDescriptor.Appearance.ColumnHeaderCell.BackgroundImage = System.Drawing.Image.FromFile("..\..\Note.jpg") columnDescriptor.Appearance.ColumnHeaderCell.BackgroundImageMode = GridBackgroundImageMode.CenterImage
Screenshot
Conclusion
I hope you enjoyed learning about how to set an image as a background for a cell in WinForms GridGroupingControl.
You can refer to our WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!