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

Deleting rows in GridDataboundGrid

These are 2 different methods i tried for deleting rows in a grid manually(say by right clicking the grid) 1) dgExpCharges.Binder.RemoveRecords(dgExpCharges.CurrentCell.RowIndex - 1, dgExpCharges.CurrentCell.RowIndex - 1) By using this I get a message saying that "There is no row at position 1" 2) table = dsChargeItemDefn.ExplodingChargeDetails If table.DefaultView.Count > (dgExpCharges.CurrentCell.RowIndex - 1) Then 'table.DefaultView.Item(dgExpCharges.CurrentCell.RowIndex - 1).Delete() By using this it sometimes deletes the non selected row. Say if i want to delete 3rd row,it would delete 1st or 2nd in a random way. Why this is happening? And how to fix this?

5 Replies

AD Administrator Syncfusion Team May 7, 2003 04:44 AM UTC

> > These are 2 different methods i tried for deleting rows in a grid manually(say by right clicking the grid) > > 1) > dgExpCharges.Binder.RemoveRecords(dgExpCharges.CurrentCell.RowIndex - 1, dgExpCharges.CurrentCell.RowIndex - 1) > > By using this I get a message saying that "There is no row at position 1" > > 2) > > table = dsChargeItemDefn.ExplodingChargeDetails > If table.DefaultView.Count > (dgExpCharges.CurrentCell.RowIndex - 1) Then > 'table.DefaultView.Item(dgExpCharges.CurrentCell.RowIndex - 1).Delete() > > By using this it sometimes deletes the non selected row. > Say if i want to delete 3rd row,it would delete 1st or 2nd in a random way. > > > > Why this is happening? And how to fix this? Though it probably is not causing a problem here (as long as you only have 1 header row), you can use grid.Binder.RowIndexToPosition to get the zero-based position from the row index. Are you using a simple GridDataBoundGrid, or is it a "Expand"-type gierarchical grid? If it is an hierarchical grid, you will have to work directly with the child lists to remove items. If it is a simple GridDataBoundGrid then I would think your first code should work. It does for me in a simple grid. Do you have some setting, like maybe teh grid is disabled or ReadOnly or something else that might be preventing the deletion? Attached is a sample that seems to work as expected. It deletes the current row from both a button and a contextmenu item.


LO Loga May 7, 2003 10:07 AM UTC

yes..Based on certain conditions i'm setting certain rows as readonly. Deletion of those readonly rows also gives problem sometimes. > > > > These are 2 different methods i tried for deleting rows in a grid manually(say by right clicking the grid) > > > > 1) > > dgExpCharges.Binder.RemoveRecords(dgExpCharges.CurrentCell.RowIndex - 1, dgExpCharges.CurrentCell.RowIndex - 1) > > > > By using this I get a message saying that "There is no row at position 1" > > > > 2) > > > > table = dsChargeItemDefn.ExplodingChargeDetails > > If table.DefaultView.Count > (dgExpCharges.CurrentCell.RowIndex - 1) Then > > 'table.DefaultView.Item(dgExpCharges.CurrentCell.RowIndex - 1).Delete() > > > > By using this it sometimes deletes the non selected row. > > Say if i want to delete 3rd row,it would delete 1st or 2nd in a random way. > > > > > > > > Why this is happening? And how to fix this? > > Though it probably is not causing a problem here (as long as you only have 1 header row), you can use grid.Binder.RowIndexToPosition to get the zero-based position from the row index. > > Are you using a simple GridDataBoundGrid, or is it a "Expand"-type gierarchical grid? If it is an hierarchical grid, you will have to work directly with the child lists to remove items. > > If it is a simple GridDataBoundGrid then I would think your first code should work. It does for me in a simple grid. Do you have some setting, like maybe teh grid is disabled or ReadOnly or something else that might be preventing the deletion? > > Attached is a sample that seems to work as expected. It deletes the current row from both a button and a contextmenu item.


AD Administrator Syncfusion Team May 7, 2003 01:02 PM UTC

Is there any way you can exclude rows that you delete from having this readonly setting? You might try setting grid.Model.DiscardReadonly = true before you call your delete code, and resetting it to false afterwards.


AD Administrator Syncfusion Team October 21, 2003 12:24 PM UTC

I noticed you said you are setting certain rows as readonly. I've been looking around how to do it and can't find any info. I'm new to Syncfusion, could you give me a hint how to set a row to readonly? Thanks in advance. Max > yes..Based on certain conditions i'm setting certain rows as readonly. > Deletion of those readonly rows also gives problem sometimes. > > > > > > > > These are 2 different methods i tried for deleting rows in a grid manually(say by right clicking the grid) > > > > > > 1) > > > dgExpCharges.Binder.RemoveRecords(dgExpCharges.CurrentCell.RowIndex - 1, dgExpCharges.CurrentCell.RowIndex - 1) > > > > > > By using this I get a message saying that "There is no row at position 1" > > > > > > 2) > > > > > > table = dsChargeItemDefn.ExplodingChargeDetails > > > If table.DefaultView.Count > (dgExpCharges.CurrentCell.RowIndex - 1) Then > > > 'table.DefaultView.Item(dgExpCharges.CurrentCell.RowIndex - 1).Delete() > > > > > > By using this it sometimes deletes the non selected row. > > > Say if i want to delete 3rd row,it would delete 1st or 2nd in a random way. > > > > > > > > > > > > Why this is happening? And how to fix this? > > > > Though it probably is not causing a problem here (as long as you only have 1 header row), you can use grid.Binder.RowIndexToPosition to get the zero-based position from the row index. > > > > Are you using a simple GridDataBoundGrid, or is it a "Expand"-type gierarchical grid? If it is an hierarchical grid, you will have to work directly with the child lists to remove items. > > > > If it is a simple GridDataBoundGrid then I would think your first code should work. It does for me in a simple grid. Do you have some setting, like maybe teh grid is disabled or ReadOnly or something else that might be preventing the deletion? > > > > Attached is a sample that seems to work as expected. It deletes the current row from both a button and a contextmenu item. >


AD Administrator Syncfusion Team October 21, 2003 01:50 PM UTC

In a GridControl, you can use the GridControl.RowStyles[row].ReadOnly property to set an entire row to readonly. In a GridDataBoundGrid, you cannot directly do this for row or cell styles, only columns styles through the GridBooundColumn object for the column. Instead if you have to use PrepareViewStyleInfo to set these row or cell properties as in this KB article http://www.syncfusion.com/KB/Grid/Grid_c35c.asp#q561q which discusses BackColor, but it also applies to other GridStyleInfo properties like ReadOnly.

Loader.
Live Chat Icon For mobile
Up arrow icon