Articles in this section

How to set the current cell backcolor to the backcolor of remaining selected cells in WinForms GridControl?

Backcolor settings

When the current cell is not in 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

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);
      }
   }
}
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,

Backcolor of selected cell is set to current cell backcolor


Figure
1: The BackColor of the selected cell is set to the BackColor of the current cell

Samples:

C#: BackColor for Selected Cells

VB: BackColor for Selected Cells

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