Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Hide the row selection arrow in DataGridView
 

Hide the row selection arrow in DataGridView

I'm using an unbound DataGridView control to allow a user to set up some properties for another screen. I am using the row header column to display the row number and I don't want the row selection arrow to appear in the row header. I set the SelectionMode property to CellSelect and so now only a single cell gets selected but the arrow still appears in the row header.

Can anyone tell me how to prevent that arrow from appearing in the row header?


SCJoe  Tuesday, January 15, 2008 7:02 PM

Just hanlding the CellPainting and do something like this:

Code Block

dataGridView1_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.ToString(),

e.CellStyle.Font, br, e.CellBounds, sf);

}

e.Handled = true;

}

}


Zhi-Xin Ye  Friday, January 18, 2008 1:23 PM

Just hanlding the CellPainting and do something like this:

Code Block

dataGridView1_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.ToString(),

e.CellStyle.Font, br, e.CellBounds, sf);

}

e.Handled = true;

}

}


Zhi-Xin Ye  Friday, January 18, 2008 1:23 PM
scjoe,
alternatively you may use a row height of less than 17 pixel, I guess that value depends on the type of borders you're using (single, 3D, sunken....). I'm using Cellborderstyle = single, columnheaderborderstyle and rowheaderborderstyle = raised which puts the threshold of having the arrow at 17 pixel height. I found that to be the only (other) way. Cheers!
swissmountaindude  Wednesday, July 22, 2009 7:05 PM

You can use google to search for other answers

Custom Search

More Threads

• Datagrid question
• Windows Forms Data Controls and Databinding FAQ
• need help with custom control
• DataGridView DataBinding Events
• Altering and/or dropping Wizard-Created binding sources
• How do I determine the order in which fields are databound?
• Complex Data Binding in VS IDE
• UpdateCommand, query and databinding...
• Right click event from a ListView item
• Setting datagrid column width ??