Articles in this section

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 the DrawCell event

2. By using the QueryCellStyleInfo event

3. By using GridColumnDescriptor


The following code examples explain how to set an image as a background for the cell by using the DrawCell event.

 

// 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");
}
'Event hooking 
AddHandler 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

The screenshot below displays the background image of the cell

Show images added in cell background



The following code examples explain how to set an image as a background for cell by using QueryCellStyleInfo event.


// 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;
   }
}
'Event hooking 
AddHandler 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

The screenshot below displays the background image of the cell

Show the images cell in GridGroupingControl


The following code examples explain how to set an image as a background for the cell by using GridColumnDescriptor property.

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;
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

The screenshot below displays the background image of the cell


Show image cell in GridGroupingControl


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’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to present and manipulate data.

 

For current customers, you can check out our WinForms 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 WinForms GridGroupingControl and other WinForms components.

 

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied