BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
I add the record rec to the data source (happens to be the last -and only one in its page-), which is accessed through a pager. Then I want to scroll the grid to that record and select it. I have tried many things but without success. The following code simply does not find it (so it does not work). Please help.
// var record = grid.View.Records.FirstOrDefault( item => ( item.Data as Persona ).personasid == personasId );
var record = objetoCN.getRegistro( personasId ); // this routine makes the previous line essentially
if( record != null ) {
//allways finds it, so it enters the if part
pager.MoveToFirstPage();
for( int p = 1; p <= pager.PageCount; ++p ) {
int ndx = grid.TableControl.ResolveToRowIndex( record );
if( ndx >= 0 ) {
grid.TableControl.ScrollRows.ScrollInView( ndx );
grid.TableControl.UpdateScrollBars();
grid.CurrentItem = record;
grid.SelectRows( ndx, ndx );
grid.SelectedItem = record;
return; // this code is in a routine
}
if( p < pager.PageCount ) pager.MoveToNextPage();
}
Thanks in advance.
Best regards,
Socrates A Rivera R
sa.riverar@gmail.com
Hi Socrates,
Your requirement to move to the newly added record and select that will be achievable by using the SfDataPager.MoveToNextPage method is shown in the below code snippet,
private void button1_Click(object sender, EventArgs e) { viewModel.OrdersListDetails.Add(new OrderInfo { OrderID = 100, CustomerID = "xxx", ProductName = "yyy", ContactNumber = 121345, Quantity = 12, ShipCountry = "zzz", UnitPrice = 10 }); for (int p = 1; p <= sfDataPager1.PageCount; ++p) { var record = sfDataGrid1.View.Records.FirstOrDefault(item => (item.Data as OrderInfo).OrderID == 100); sfDataPager1.MoveToNextPage(); if (record != null) sfDataGrid1.SelectedItem = record.Data; } } |
We have prepared the sample based on the above suggestion, please have a
look at this.
Regards,
Dhanasekar M.
If this post is helpful, please consider Accepting it as the solution so that
other members can locate it more quickly.
Hello Dhanasekar,
Thank you very much for your help.
It helped me to see my mistakes. Your solution still have some problems (among others I do not always insert records at the end of recordset (nor first position in page).
I prepared a solution with your suggestions (is attached).
Thank you very much again.
Best regards,
Sócrates A Rivera R
Socrates,
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help.