Tuesday, May 25, 2010

Merge Cell In DataGridView

To merge Cell in DataGridView You Have to Fire Paint event


after that give the RowHeight and RowWidth and number of cell to be merged

Code is Given below

dataGridView1.Paint += new PaintEventHandler(dataGridView1_Paint);

void dataGridView1_Paint(object sender, PaintEventArgs e)

{

Rectangle rct;

rct = e.ClipRectangle;

rct.X = dataGridView1.GetColumnDisplayRectangle(0, true).X;



rct.Y = dataGridView1.GetRowDisplayRectangle(6, true).Y;//here 6 is the ROW Number which you want to Merge


rct.Height = dataGridView1.Rows[1].Height;//.Cells[0].Size.Height;


rct.Width = dataGridView1.Rows[2].Cells[0].Size.Width * 4;// 4 is the no of cell to be merged

OR

rct.Width = dataGridView1.Width; // its Automatically Merge all the Cell of a ROW

e.Graphics.FillRectangle(Brushes.White, rct);


Pen p = new Pen(SystemColors.ControlDark);

e.Graphics.DrawRectangle(p, rct);
e.Graphics.DrawString("Total Salary  " + SalarySum,new System.Drawing.Font("Arial",10,FontStyle.Bold ) ,Brushes.Blue, rct.X, Rect.Y);
}

No comments:

Post a Comment

Mat Table Angular

Mat Table in Angular Mat table is used to display data . its a material designed styled data-table . For using Material Table MatTableMo...