We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to display index and images on Row Header?

Hello Dear support.
Firstly, I would thank you for your good support !
Secondly, I have the following quastions :
 1) How to show the numbred Row Header and icons in the same RowHeader Cell?
 2) How to resize automatically the RowHeader Cell to fit its contnent ?
Best regards

1 Reply

SA Saravanan Ayyanar Syncfusion Team January 10, 2020 02:23 PM UTC

Hi Cosyspro, 
 
Thank you for using Syncfusion controls. 
 
Please find the below your query response, 
 
Query  
Response 
 
How to show the number Row Header and icons in the same RowHeader Cell ? 
 
You can achieve your requirement of “Show the numbers and Icons in the same RowHeaderCell by using the DrawCell event. Please refer the below code snippet. Please find the sample link below the table. 
 
sfDataGrid.DrawCell += sfDataGrid_DrawCell; 
 
void sfDataGrid_DrawCell(object sender, Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs e) 
{ 
    if (sfDataGrid.ShowRowHeader && e.RowIndex != 0) 
    { 
        if (e.ColumnIndex == 0) 
        { 
            e.Handled = true; 
            Rectangle rect = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 10, e.Bounds.Width - 3, e.Bounds.Height - 5); 
            e.Graphics.FillRectangle(new SolidBrush(sfDataGrid.Style.RowHeaderStyle.BackColor), new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 1, e.Bounds.Height - 1)); 
            e.Graphics.DrawImage(new Bitmap(Image.FromFile(@"../../search.png")), e.Bounds.X + 30, e.Bounds.Y +3); 
            e.Graphics.DrawString(e.RowIndex.ToString(), new System.Drawing.Font("Calibri", 12), new System.Drawing.SolidBrush(System.Drawing.Color.Black), e.Bounds.X + 3, e.Bounds.Y+5);   
            e.Graphics.DrawLine(new Pen(ColorTranslator.FromHtml("#CCCCCC")), e.Bounds.Right, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom); 
            e.Graphics.DrawLine(new Pen(ColorTranslator.FromHtml("#CCCCCC")), e.Bounds.Left, e.Bounds.Bottom, e.Bounds.Right, e.Bounds.Bottom); 
        } 
    }             
} 
 
UG Link: 
 
 
How to resize automatically the RowHeader Cell to fit its content ? 
Currently, we are not provided the support to resize the RowHeaderCell. You can achieve your requirement  by setting the SfDataGrid.HeaderRowWidth. Please refer the below code snippet. Please find the sample link below the table. 
 
 
sfDataGrid.RowHeaderWidth = 70; 
 
 
UG Link: 
 
 
Sample Link: 
 
Screenshot: 
 
 
 
Please let us know, if you require further assistance on this. 
 
Regards, 
Saravanan A. 


Loader.
Live Chat Icon For mobile
Up arrow icon