I am reloading the data source if the row id is empty, but it is not deleted from the view after it is deleted from the database
and selection is not changed after row is deleted
public void DataRowDelete(Syncfusion.WinForms.DataGrid.SfDataGrid _dtg, Action _action, Form _owner)
|
Query |
Response | |
|
I am reloading the data source if the row id is empty, but it is not deleted from the view after it is deleted from the database
and selection is not changed after row is deleted |
By Default, SfDataGrid.View.RemoveAt() method can be used to remove a record from the view and we have ensured that this is working fine at our end and tested in the below attached sample.
We are little bit unclear about your requirement and your provided code example is not clear since some of the variable and methods are not included.
Could you please let us know, issue experiencing is whether the record is not removed using View.RemoveAt or you expect the selection should remain after row is deleted?
This will be very helpful for us to sort out the issue at the earliest. | |
|
rowstyle doesn't work after remove row |
The reported behavior of RowStyle event customization after a row deleted is a default behavior.
Here, the above color change occurs due to change in row index of the rows below the deleted row. At first, the alternative rows will be rendered in WhiteSmoke color. But when a row is deleted from grid, the row index of the below rows will be changed. (i.e. Row index of the below rows would be changed from odd to even and even to odd).
Since the row index of below rows are changed now, WhiteSmoke color is changed to current even rows also.
To have alternate row colors even when deleting rows, please use the below code example.
Code Example:
|
These are the methods I use. my problem is after the row is deleted, new row not automatically selected. I've used the following methods to solve this problem but after delete three row it's not working.
private void SfDataGridController_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (Newrowadding) { Newrowadding = AddNewRow(e); } if (e.Action == NotifyCollectionChangedAction.Remove) { //dtgrid.SelectedIndex = dtgrid.TableControl.ResolveToRecordIndex(dtgrid.SelectedIndex)+1; } }
| public void DataRowDelete() { if (dtgrid.SelectedItem != null) { System.Data.DataRow dataRow = (dtgrid.SelectedItem as DataRowView).Row; if (!AreAllColumnsEmpty(dataRow)) { int SelectedRowId = Convert.ToInt32(dataRow[0]); var res = MessageBoxController.ShowQuestionMessage("Bu satırı silmek istediğinizden emin misiniz?"); if ((DialogResult)res == DialogResult.Yes) { using (ProgressManager progmanager = new ProgressManager()) { progmanager.StartProgress(Ownerfrm); int _Dgdeletingrowindex = dtgrid.TableControl.ResolveToRecordIndex(dtgrid.SelectedIndex); Dictionary p.Add("rowid", SelectedRowId); sql.ExecuteDataTable(DeleteProcName, p); dtgrid.View.RemoveAt(_Dgdeletingrowindex); progmanager.CloseProgress(); } } else { dtgrid.CurrentCell.EndEdit(); } } } } |
_dtg.SelectedItem =_dtg.View.Records.GetItemAt( _dtg.TableControl.ResolveToRecordIndex(_dtg.SelectedIndex));