Category / Section
How to set the current cell backcolor to the backcolor of remaining selected cells in WinForms GridControl?
1 min read
Backcolor settings
When the current cell is not in an edit mode, it is generally a part of the selection. When you want to set the BackColor like the other selected cells then, you have to use the CellDrawn event
C#
void gridControl1_CellDrawn(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e) { //get the currentcell GridCurrentCell cc = this.gridControl1.CurrentCell; if (e.RowIndex == cc.RowIndex && e.ColIndex == cc.ColIndex) { //fill the selection color to the cells background using (SolidBrush br = new SolidBrush(this.gridControl1.AlphaBlendSelectionColor)) { e.Graphics.FillRectangle(br, e.Bounds); } } }
VB
Private Sub gridControl1_CellDrawn(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs) 'get the currentcell Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell If e.RowIndex = cc.RowIndex AndAlso e.ColIndex = cc.ColIndex Then 'fill the selection color to the cells background Using br As New SolidBrush(Me.gridControl1.AlphaBlendSelectionColor) e.Graphics.FillRectangle(br, e.Bounds) End Using End If End Sub
After applying the properties, the Grid is shown as follows,
Figure 1: The BackColor of the selected cell is set to the BackColor of the current cell
Samples: