Hi,
I have a DrawCell event that creates some color schemes for some cells while loading the grid.
Now what happens is that while selecting, it got covered by the color scheme defined in "Selectionstyle"
The requirement is that while selecting, Color should remain for those cells and the selectionstyle need to apply for remaining cells.
Is it possible ?
Selection Settings :
SelectionMode --> Single
SelectionUnit --> Row
Thanks,
An
|
sfDataGrid.DrawCell += SfDataGrid_DrawCell;
private void SfDataGrid_DrawCell(object sender, Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs e){
if (e.Column.MappingName == "CustomerName" || e.Column.MappingName == "Country")
{
if (e.DisplayText == "Thomas Hardy" || e.DisplayText == "Mexico")
{
e.Style.BackColor = Color.Coral;
e.Style.TextColor = Color.White;
StringFormat format = new StringFormat();
DrawingHelper drawingHelper = new DrawingHelper();
if (e.Column.CellType == "Numeric")
e.Style.HorizontalAlignment = HorizontalAlignment.Right;
var horizontalAlignment = drawingHelper.GetType().GetMethod("ConvertToStringAlignment", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(HorizontalAlignment) }, new ParameterModifier[] { }).Invoke(drawingHelper, new object[] { e.Style.HorizontalAlignment });
var verticalAlignment = drawingHelper.GetType().GetMethod("ConvertToStringAlignment", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(VerticalAlignment) }, new ParameterModifier[] { }).Invoke(drawingHelper, new object[] { e.Style.VerticalAlignment });
format.Alignment = (StringAlignment)horizontalAlignment;
format.LineAlignment = (StringAlignment)verticalAlignment;
e.Graphics.FillRectangle(new SolidBrush(e.Style.BackColor), e.Bounds);
e.Graphics.DrawString(e.DisplayText, e.Style.GetFont(), new SolidBrush(e.Style.TextColor), e.Bounds, format);
e.Graphics.DrawLine(new Pen(e.Style.Borders.Right.Color), e.Bounds.Right - 1, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Bottom);
e.Graphics.DrawLine(new Pen(e.Style.Borders.Bottom.Color), e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
//Handling the event
e.Handled = true;
}
}
} |