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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Problem with deleting rows in databound grid

Thread ID:

Created:

Updated:

Platform:

Replies:

3357 Mar 13,2003 10:26 PM UTC Mar 14,2003 07:18 PM UTC WinForms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On March 13, 2003 10:26 PM UTC

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

Administrator [Syncfusion]
Replied On 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");
	}
}

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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);

Administrator [Syncfusion]
Replied On March 14, 2003 07:18 PM UTC

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;