C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Piant event of Datagrid view to merge the Header


Posted Date: 21 May 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Abhishek AryaMember Level: Diamond    
Rating: 1 out of 5Points: 10




void dataGridView1_Paint(object sender, PaintEventArgs e)

{

//Get the cell bounds of the header cell in column3

Rectangle r1 = this.dataGridView1.GetCellDisplayRectangle(2, -1, true);

//Get the cell bounds of the header cell in column4

Rectangle r2 = this.dataGridView1.GetCellDisplayRectangle(3, -1, true);

r1.X += 1;

r1.Y += 2;

r1.Width += r2.Width - 2;

r1.Height -= 6;



//cover the rectangle right over the headers.

using (SolidBrush br = new SolidBrush(

this.dataGridView1.ColumnHeadersDefaultCellStyle.BackColor))

{

e.Graphics.FillRectangle(br, r1);

}

//draw text

using (SolidBrush br = new SolidBrush(

this.dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor))

{

StringFormat sf = new StringFormat();

sf.LineAlignment = StringAlignment.Center;

sf.Alignment = StringAlignment.Center;

e.Graphics.DrawString("merged header",

this.dataGridView1.ColumnHeadersDefaultCellStyle.Font, br, r1, sf);

}

}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to find the value using regular expression
Previous Resource: Re-Usable Class for Sending Emails using ASP.Net 2.0
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use