How can i delete the rows in gridview using contextmenustrip control(windows applications)

Posted by Sudheep.grandhe under C# on 12/15/2011 | Points: 10 | Views : 2531 | Status : [Member] | Replies : 1
Hi,

I am adding a contextmenustrip control to my form and i wrote the following code to it.But,it wont work.whether i have to create delete button like that are no need .please do the needful.
public partial class NewInvoice : Form
{

DataTable dtblGrid = new DataTable();
DataGridView.HitTestInfo hitTestInfo;


private void NewInvoice_Load(object sender, EventArgs e)
{
AuthorDetailsDataTableColumns();
AddItemDetailsGridViewColumns();
contextMenuStrip1.Items.Add("Delete", null, new EventHandler(Delete));//here shows an error:Error 2 No overload for 'Delete' matches delegate 'System.EventHandler'

}
private void GridView1_MouseUp(object sender, MouseEventArgs e)
{
if (e .Button ==MouseButtons .Right )
{
hitTestInfo =GridView1 .HitTest (e .X ,e .Y );
{
if (hitTestInfo .RowIndex >= 0)
if (!GridView1 .Rows [hitTestInfo .RowIndex ].IsNewRow )
{
if (hitTestInfo .Type ==DataGridViewHitTestType .RowHeader && hitTestInfo .RowIndex ==hitTestInfo .RowIndex )
contextMenuStrip1 .Show (GridView1,new Point (e .X ,e .Y ));
}
}
}
}

private void AuthorDetailsDataTableColumns()
{
dtblGrid.Columns.Add("compname", typeof(string));
dtblGrid.Columns.Add("compaddress", typeof(string));
dtblGrid.Columns.Add("invoiceno", typeof(string));
dtblGrid.Columns.Add("perprice", typeof(string));
dtblGrid.Columns.Add("quantity", typeof(string));
dtblGrid.Columns.Add("amount", typeof(string));
dtblGrid.Columns.Add("invoicedate", typeof(string));
dtblGrid.Columns.Add("ondate", typeof(string));
dtblGrid.Columns.Add("orderno", typeof(string));
}
void Delete()
{
if (!GridView1.Rows[hitTestInfo.RowIndex].IsNewRow)
{
GridView1.Rows.RemoveAt(hitTestInfo.RowIndex);
}
}
private void AddItemDetailsGridViewColumns()
{
DataGridViewTextBoxColumn dgvcompanyname = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvcompaddress = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvinvoiceno = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvorderno = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvinvoicedate = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvondate = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvparticulars = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvquantity = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvperprice = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn dgvamount = new DataGridViewTextBoxColumn();




}

Best,
Sudheep.



Responses

Posted by: Naraayanan on: 12/29/2011 [Member] Starter | Points: 25

Up
0
Down
HI
Check this linkhttp://msdn.microsoft.com/en-us/library/5s3ce6k8.aspx#Y2964

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response