Hi
I m completely new to C#.Net, and I couldnt find " RowCreated" Event Handler for my DataGridView.
So, I created a new Event Handler, but now I dont know how to call it.
pls help me out... Below is my code ...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web.UI.WebControls;
namespace DgvColumnHeaderMerge
{
public partial class DgvColumnHeaderMerge : Form
{
public event GridViewRowEventHandler RowCreated;
public DgvColumnHeaderMerge()
{
InitializeComponent();
}
private void DgvColumnHeaderMerge_Load(object sender, EventArgs e)
{
DgvColumnHeaderMerge d_obj = new DgvColumnHeaderMerge();
this.dataGridView2.Columns.Add("dept_name", "Name");
this.dataGridView2.Columns.Add("dept_code", "Code");
this.dataGridView2.Columns.Add("emp_name", "Name");
this.dataGridView2.Columns.Add("emp_place", "Place");
this.dataGridView2.Columns.Add("emp_phone", "Phone No");
}
void dataGridView2_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView oGridView = (GridView)sender;
GridViewRow oGridViewRow =
new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell oTableCell = new TableCell();
oTableCell.Text = "Department";
oTableCell.ColumnSpan = 2;
oGridViewRow.Cells.Add(oTableCell);
oTableCell = new TableCell();
oTableCell.Text = "Employee";
oTableCell.ColumnSpan = 3;
oGridViewRow.Cells.Add(oTableCell);
oGridView.Controls[0].Controls.AddAt(0, oGridViewRow);
}
}
}
}
I want the output as following,
---------------------------------------------------------------
Department | Employee |
---------------------------------------------------------------
Name | Code | Name | Place | Phone No |
---------------------------------------------------------------
| | | | |
---------------------------------------------------------------
| | | | |
---------------------------------------------------------------
Kindly help me correct my mistakes.
Thanks and Regards,
Kavya Shri
Thread: Merging headers in datagridview of C#.net
Forum: C#