Trying to keep focus at bottom of datagrid when new rows are added

How do I keep the focus at the bottom of a datagrid by default whenever new rows are added to the datagrid?


7 Replies

VS Vijayarasan Sivanandham Syncfusion Team March 14, 2022 04:49 PM UTC

Hi Franklin J Moormann,

We are a little unclear with your requirement. Can you please provide the more information related to your query?

Can you please share us below things?         
  1. Details about your scenario with illustrations
  2. Confirm whether your application is a AddNewRowSupport enabled  or not
  3. Share your exact requirement
                 
It will be helpful for us to check on it and provide you the solution at the earliest. 
 
Regards, 
Vijayarasan S 



CH cheatcountry March 16, 2022 07:41 PM UTC

I'm simply trying to keep the focus at the bottom of the datagrid by default and especially when new rows are added. This is what I'm currently seeing now: https://prnt.sc/mcZGCqRbq0zg


I don't know if my application is AddNewRowSupport enabled or not



VS Vijayarasan Sivanandham Syncfusion Team March 17, 2022 02:47 PM UTC

Hi Franklin J Moormann,

Provided details are insufficient to find the exact requirement of your scenario. Provide more information related to your query?
 
  • Code snippet related to customization of SfDataGrid
  • Details about your scenario with illustrations       
Kindly revert to us with the above requested details. It will be more helpful for us to check the possibilities to resolve the reported problem.

Regards,
Vijayarasan S
 



BO bob replied to Vijayarasan Sivanandham March 20, 2022 04:47 PM UTC

When a new row is added to the SF datagrid he want the scrollbar at the bottom .  So this way the user don't need to scroll down to see new rows added


// using a standard datagrid we are able to set the scrollbar to the bottom 

 dataGridViewInfo.FirstDisplayedScrollingRowIndex = dataGridViewInfo.RowCount - 1;



VS Vijayarasan Sivanandham Syncfusion Team March 21, 2022 03:33 PM UTC

Hi Cheatcountry / bob,

Your requirement to scroll to last data row when adding new row in SfDataGrid can be achieved by customize the CollectionChanged event in SfDataGrid.View. Please refer the below code snippet,

 
sfDataGrid1.View.Records.CollectionChanged += OnCollectionChanged; 
 
private void OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
{ 
            //here scroll to a last record programmatically while new row added in SfDatGrid 
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 
            {                
                this.sfDataGrid1.BeginInvoke(new Action(() => 
                { 
                    //here get the last rowindex of SfDataGrid 
                    var lastRowIndex = this.sfDataGrid1.TableControl.ResolveToRowIndex(sfDataGrid1.View.Records.Count);                     
                    //scroll to a last record in DataGrid using the SfDataGrid.TableControl.ScrollRows.ScrollInView 
                    this.sfDataGrid1.TableControl.ScrollRows.ScrollInView(lastRowIndex); 
                    this.sfDataGrid1.TableControl.UpdateScrollBars(); 
 
                })); 
            } 
} 
Vijayarasan S 



CH cheatcountry replied to bob March 21, 2022 05:55 PM UTC

Yes this is exactly what I mean. I was trying to explain it several times but not well enough I guess that when a new item is added to the datarow the focus stays at the items at the top of the datagrid but I want to keep the focus at the bottom of the datagrid instead. I also know how to do it with a normal datagrid but trying to ask syncfusion how to do it with their datagrid



BO bob March 21, 2022 07:36 PM UTC

ALL IN 


Loader.
Up arrow icon