6/08/2013

C# - Hide the row selection arrow in DataGridView

C# Hide the row selection arrow in DataGridView
C# Hide the row selection arrow in DataGridView

 private void DataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)  
     {  
       //this.DataGridView.Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex+1).ToString();   
     }  
     private void DataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)  
     {  
       if (e.ColumnIndex == -1 && e.RowIndex > -1)  
       {  
         e.PaintBackground(e.CellBounds, true);  
         using (SolidBrush br = new SolidBrush(Color.Black))  
         {  
           StringFormat sf = new StringFormat();  
           sf.Alignment = StringAlignment.Center;  
           sf.LineAlignment = StringAlignment.Center;  
           e.Graphics.DrawString((e.RowIndex+1).ToString(),  
             e.CellStyle.Font, br, e.CellBounds, sf);  
         }  
         e.Handled = true;  
       }  
     }  

No comments:

Post a Comment