Hi,
are we going to see an update for sfdatagrid to update the position on the bindingsource automatically?
thanks.
Hi Ehs psy,
We suspect that your requirement is to update the current position in the related
binding source. By default, SfDataGrid does not change the current position in
the related binding source.
However, your requirement to update the current position in the related binding
source in SfDataGrid can be achieved by customizing the DrawCell event in
SfDataGrid. Please refer to the below code snippet,
|
sfDataGrid1.DrawCell += OnDrawCell;
private void OnDrawCell(object sender, DrawCellEventArgs e) { var dataGrid = sender as SfDataGrid; //here customize based on your scenario if (dataGrid.CurrentItem != null && dataGrid.CurrentCell != null && dataGrid.CurrentCell.RowIndex == e.RowIndex && e.ColumnIndex == dataGrid.CurrentCell.ColumnIndex ) { //here get the index of CurrentItem var index = bindingSource1.CurrencyManager.List.IndexOf(dataGrid.CurrentItem); //here set the current item index into Position of bindingSource1 bindingSource1.Position = index; } } |
Please find the sample in the attachment.
API Link: https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.SfDataGrid.html#Syncfusion_WinForms_DataGrid_SfDataGrid_DrawCell
UG Link: https://help.syncfusion.com/windowsforms/datagrid/databinding
If we misunderstood your requirement, please provide more information regarding
the requirement. This would help us to proceed further.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the
solution so that other members can locate it more quickly.
Hi Vijayarasan Sivanandham ;
var index = bindingSource1.CurrencyManager.List.IndexOf(dataGrid.CurrentItem);
that will loop through the dataset to get the index.
what if we have thousands of rows !!!!!!!!
thank you .
Hi Ehs psy,
The provided suggestion should not cause any kind of performance issue
depending on the rows count. However, you can achieve your requirement with the
help of the ResolveToRecordIndex helper method shown below,
|
private void OnDrawCell(object sender, DrawCellEventArgs e) { var dataGrid = sender as SfDataGrid; //here customize based on your scenario if (dataGrid.CurrentItem != null && dataGrid.CurrentCell != null && dataGrid.CurrentCell.RowIndex == e.RowIndex && e.ColumnIndex == dataGrid.CurrentCell.ColumnIndex ) { //here get the index of CurrentItem //below mentioned way does not affect any performance issue depending on the rows count //var index = bindingSource1.CurrencyManager.List.IndexOf(dataGrid.CurrentItem); //here set the current item index into Position of bindingSource1 //bindingSource1.Position = index;
//here get the recordindex of the current item var recordIndex = dataGrid.TableControl.ResolveToRecordIndex(e.RowIndex); bindingSource1.Position = recordIndex;
} } |
UG Link: https://help.syncfusion.com/windowsforms/datagrid/helpers
But this way has some limitations, whenever you are grouping
the records, the index gets mismatched. Because when you are grouping the
records summary rows are added in SfDataGrid. In this case, it will returns the
current index of record that is present in the view.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
I hope you will do it, it will facilitate a lot of things
Even if your solution work's it will become more difficult to deal with if your app became more complex
regards
Hi Mark,
If you encounter any problems with the solution provided, please provide the
details. We would be glad to assist you.
Regards,
Vijayarasan S