Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView: remove the padding in RowHeaderCell?
 

DataGridView: remove the padding in RowHeaderCell?

Hi!
After googling around and looking at previous posts here, I once more must resort to this forum...

I have created a custom DGV where I have implemented an inherited DataGridViewRowHeaderCell class. In this class, I have overrided the Paint method so I don't get that arrow icon in the RowHeaders (paintParts &= ~DataGridViewPaintParts.ContentBackground;) However, when I add headers to the Row header cells, this text doesn't align to the left! Instead, the text starts at the middle of the Row header cell, as if the arrow/star icon was still there.

How can I adjust the row header cells so that they are aligned to the left? I guess I have to modify the paint method further, but how? I have experimented with the cellBounds and clipBounds rectangles but it just turns out very strange...

My current paint method in my custom DataGridViewRowHeaderCell class is as follows:

            protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
            {
                // Remove the part where the background (icon) is drawn from the paintParts object
                paintParts &= ~DataGridViewPaintParts.ContentBackground;
                
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            }
 
Ekoman  Sunday, April 05, 2009 11:07 PM

Hi,

Base on my understanding, you need to draw text with stringFormat. LineAlignment flag.

You can get the information about draw the text, from faq2: How can I show vertical text in the cell?

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Saturday, April 11, 2009 1:24 PM

Hi,

Base on my understanding, you need to draw text with stringFormat. LineAlignment flag.

You can get the information about draw the text, from faq2: How can I show vertical text in the cell?

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Saturday, April 11, 2009 1:24 PM

You can use google to search for other answers

Custom Search

More Threads

• ScrollBars do not show in DGV
• Column Order in Databind
• BindingSource question about saving updates.
• how to represent 2 D data in Grid View?
• Serious Problem with TableAdapter and BindingSource
• Running Total??
• How to format the way to diplay a string ?
• Annotations lost for Typed Datasets using Web Services
• String to Formula?
• DataGridView duplicated columns issue - what's the fix/workaround?