Inserting and Deleting a Row With the Help of Context Menu

Hai, I am using ur product and I want a piece of code where I can insert and delete a row with the help of the Context Menu Thanks and Regards, Hsee

8 Replies

AD Administrator Syncfusion Team July 2, 2004 08:23 AM UTC

What rid control are you using? GridControl, GridDataBoundGrid or GridGroupingControl? There are different technique requred for each type of grid as they use different data sources.


AR arvind July 2, 2004 08:40 AM UTC

I am using GridDataBoundGrid.Could u please update on yhe information provided. >What rid control are you using? GridControl, GridDataBoundGrid or GridGroupingControl? > >There are different technique requred for each type of grid as they use different data sources.


AD Administrator Syncfusion Team July 2, 2004 12:00 PM UTC

Here is a sample. DeleteContext_5448.zip


AR arvind July 3, 2004 06:21 AM UTC

After inserting two rows ,when i try 2 add some values to the cell it throws an error and the newly added values move to the last row.Could you help me with this problem. Thanks, Hsee


AD Administrator Syncfusion Team July 3, 2004 12:04 PM UTC

Adding a RowLeave event handler and making a slight change in the menuhandler made the sample work ok for me.
private void menuItem2_Click(object sender, System.EventArgs e)
{
	//insert
	if(this.mouseDownRow > -1 && this.mouseDownCol > -1)
	{
		int position = this.gridDataBoundGrid1.Binder.RowIndexToPosition(mouseDownRow);
		this.gridDataBoundGrid1.BeginUpdate();
		DataRow dr = dt.NewRow();
		this.dt.Rows.InsertAt(dr, position);
		this.dt.AcceptChanges(); 
		this.gridDataBoundGrid1.EndUpdate();
	}
}

private void gridDataBoundGrid1_RowLeave(object sender, GridRowEventArgs e)
{
	dt.AcceptChanges();
}


AR arvind July 5, 2004 02:05 AM UTC

Hai the peice of code works only when u have more than one row and while u r updating the first row the attached werror will be dispalyed. Could you find any solutions if possible for this untitled_1939.zip


AD Administrator Syncfusion Team July 5, 2004 06:17 AM UTC

Try this code in Row_Leave.
private void gridDataBoundGrid1_RowLeave(object sender, GridRowEventArgs e)
{
	if(this.dt.Rows.Count > 0)
		dt.AcceptChanges();
}


AR arvind August 20, 2004 09:34 AM UTC

If I have the dataTable.AcceptChanges() in the row leave event ,then all the rows in the dataTable will have row State as Unchanged ,this is making my saving difficult. >Try this code in Row_Leave. >
>private void gridDataBoundGrid1_RowLeave(object sender, GridRowEventArgs e)
>{
>	if(this.dt.Rows.Count > 0)
>		dt.AcceptChanges();
>}
>

Loader.
Up arrow icon