We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem with deleting rows in databound grid

Hi, I have a databound grid. I am having problem with deleting rows from the grid using dataset. Please execute my attached code. When I click my delete button 4 times, it looks like it is deleting the rows. Then when I try to enter values into new-row, and click on the newly-added second new-row, the values are disappearing. Can you see my delete button code and tell me if I am doing something wrong. thanks, - Reddy

4 Replies

AD Administrator Syncfusion Team March 14, 2003 07:47 AM UTC

Instead of trying to go through the currencymanager and datarowview, you can use the Binder.RemoverRecords method to delete rows. The code below worked for me.
private void deleteBT_Click(object sender, System.EventArgs e)
{
	DataTable table = (DataTable) gridDataBoundGrid1.DataSource;
	int curRowIndex = gridDataBoundGrid1.CurrentCell.RowIndex;
	if (gridDataBoundGrid1.Model.RowCount > 1 && curRowIndex > 0
		&& gridDataBoundGrid1.Model.RowCount > curRowIndex )
	{
		int recNumber = this.gridDataBoundGrid1.Binder.RowIndexToPosition(curRowIndex);
		this.gridDataBoundGrid1.Binder.RemoveRecords(recNumber, recNumber);
	}
	else
	{
		Console.WriteLine("No More rows / CurCell is not set");
	}
}


AD Administrator Syncfusion Team March 14, 2003 01:44 PM UTC

Clay, Thank you very much for your response. I am able to Delete rows now. There is a problem with setting the Current cell now. I modified the code a little bit. 1. Run the attached application. 2. Click "Format Grid" button. It sets the data properly. I current cell is not getting set even though I made a call to CurrentCell.MoveTo(1, 1). 3. Click delete button. Nothing happens until you clik on a row. How do I set the focus to first row after call the format grid, so that my delete will work after I format grid? Am I doing something different? thanks, - Reddy


AD Administrator Syncfusion Team March 14, 2003 03:19 PM UTC

The grid does not have focus because you clicked on the button. This prvents the CurrentCell.MoveTo from properly actibvating the cell. So try setting the focus before moving the current cell. gridDataBoundGrid1.Focus(); gridDataBoundGrid1.CurrentCell.MoveTo(1, 1);


AD Administrator Syncfusion Team March 14, 2003 07:18 PM UTC

Clay, Thank you very much for responding quickly as usual. cheers, - Reddy

Loader.
Live Chat Icon For mobile
Up arrow icon