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

GDBG. Deleting current row from nested table.

Hi All. I Delete current row from nested table by this code private void btnDeleteSelectedRow_Click(object sender, System.EventArgs e) { int rowIndex = gridDataBoundGrid1.CurrentCell.RowIndex; GridBoundRecordState rs = gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(rowIndex); if( rs.ListManager.Current is DataRowView ) { DataRowView drv = (DataRowView)rs.ListManager.Current; if( drv.Row is Dataset1.QuoteRow ) // if row is from nested table { drv.Row.Delete(); gridDataBoundGrid1.Refresh(); } } } BUT, after deleting in the deleted row position I can see empty row. Why? You can test this bug in the next example DeletingNestedRows_3771.zip Regards, Slava.

3 Replies

AD Administrator Syncfusion Team May 17, 2004 03:51 AM

To refresh this child table, you have open and close the parent node. Here is some code.
private void btnDeleteSelectedRow_Click(object sender, System.EventArgs e)
{
	int rowIndex = gridDataBoundGrid1.CurrentCell.RowIndex;
	GridBoundRecordState rs = gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(rowIndex);
	if( rs.ListManager.Current is DataRowView  )
	{
		DataRowView drv = (DataRowView)rs.ListManager.Current;
		if( drv.Row is Dataset1.QuoteRow )
		{
			drv.Row.Delete();
			//find parent and close & open it
			int level = rs.LevelIndex;
			if(level == 0)
				gridDataBoundGrid1.Refresh();
			else
			{
				int row = rowIndex - 1;
				while (row > this.gridDataBoundGrid1.Model.Rows.HeaderCount)
				{
					rs = gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(row);
					if(rs.LevelIndex < level)
					{
						this.gridDataBoundGrid1.BeginUpdate();
						this.gridDataBoundGrid1.CollapseAtRowIndex(row);
						this.gridDataBoundGrid1.ExpandAtRowIndex(row);
						this.gridDataBoundGrid1.EndUpdate();
						this.gridDataBoundGrid1.Refresh();
						this.gridDataBoundGrid1.CurrentCell.MoveTo(rowIndex, 1);
						break;
					}
					row--;
				}
			}
		}
	}
}
Here is a forum reference on how to add child rows to an empty child table. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=13894 Here is a sample that shows hold you can insert/delete current rows at any level. updateableexpandgrid631958659068073824.zip


SI Silenter May 17, 2004 04:43 AM

Ok. Thanks a lot. It works. BTW, it difficult enough and it makes my code more difficult . Why I must care about it? Does syncfusion have plans to support this automatically? Regards, Slava.


AD Administrator Syncfusion Team May 17, 2004 05:01 AM

You can take the above code and put it in a method, void RefreshChildTableAtRowIndex(int rowIndex). Then your code will look innocuous like: drv.Row.Delete(); this.grid.RefreshChildTableAtRowIndex(rowIndex); We will look into adding such a method, but adding something that would ''auto respond'' to ListChanged event removing rows in this manner may not be appropriate in all situations. Just exposing the RefreshChildTableAtRowIndex would give you the option of calling it when it is needed.

Loader.
Live Chat Icon For mobile
Up arrow icon