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
close icon

We want to add an employee entry to the top of the SfDataGrid in winforms.

Sample path : Syncfusion\Windows\17.2.0.28\DataGrid.WinForms\Samples\Getting Started

We want to add an employee entry to the top of the SfDataGrid.
I want to add an employee entry programmatically at the top without using a data source.
Wpf examples can be found, but winforms examples are hard to find.
I would like some sample code.
thank you.



5 Replies

FP Farjana Parveen Ayubb Syncfusion Team July 11, 2019 09:46 AM UTC

Hi Smart, 
 
Thank you for using Syncfusion controls. 
 
We can able to add the records programmatically at top of the SfDataGrid by using SfDataGrid.View.Records, please refer the below code example 
 
private void button1_Click(object sender, EventArgs e) 
{ 
    var record = sfDataGrid.View.CreateRecordEntry(new Employee(false, "Tamer", "Manager", "tamer@il.com", "US", "Perfect", 4, "High", 2000, 20000, "1029 - 12th Ave. S.", "Male")); 
    sfDataGrid.View.Records.Insert(0, record); 
} 
 
 
Regards, 
Farjana Parveen A  



SL Smart law developer July 11, 2019 05:36 PM UTC

Thank you for answer. If you run your example, there is a problem.

The problem is that when you click on the column head to reorder it, all the records you added will be lost.


DB Dinesh Babu Yadav Syncfusion Team July 12, 2019 11:53 AM UTC

Hi Smart, 
 
We regret for the inconvenience caused. 
 
We have analyzed your query to add new row programmatically without using data source. We suspect that you do not want to insert rows into the underlying collection and this requirement can be achieved by adding unbound rows. Please refer to the below UG links to know more details on Unbound rows  
 
UG Link: 
 
Can you please confirm whether you are adding rows programmatically in WPF SfDataGrid as mentioned in the below forum?  
 
Forum Link: 
 
If yes, in that forum, we have suggested to use SfCellGrid and the requirement to add new rows programmatically without using underlying collection can be achieved only through Unbound rows for WPF SfDataGrid also. 
 
Also if we misunderstood your requirement, please let us know with more details. 
 
Regards, 
Dinesh Babu Yadav. 



SL Smart law developer August 2, 2019 07:12 AM UTC

I saw it late. Thank you


FP Farjana Parveen Ayubb Syncfusion Team August 2, 2019 07:24 AM UTC

Hi Smart, 
 
Thanks for the update. 
 
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 you. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon