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

How add new row programmatically in SfDataGrid ?


Hello Syncfusion team.

for example I add new col:

Dim col As New Syncfusion.UI.Xaml.Grid.GridTextColumn
col.HeaderText = "test col"
sfGrid.Columns.Add(col)

how to add a row in this column?

Thanks!


6 Replies

JG Jai Ganesh S Syncfusion Team October 10, 2016 10:47 AM UTC

Hi Azem, 
You can achieve your requirement for adding a new row at rime like  blow, 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
  (this.sfGrid.DataContext as UserInfoViewModel).UserDetails.Add(new UserInfo() { UserId=4001, Name="George", DateofBirth=DateTime.Now, City="Kolalambur",Salary=52000 }); 
} 
 
Also we already have a kb to add the new row programmatically, 
Kb Link: 
Regards, 
Jai Ganesh S 



AZ Azem replied to Jai Ganesh S October 15, 2016 04:00 PM UTC

Hi Azem, 
You can achieve your requirement for adding a new row at rime like  blow, 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
  (this.sfGrid.DataContext as UserInfoViewModel).UserDetails.Add(new UserInfo() { UserId=4001, Name="George", DateofBirth=DateTime.Now, City="Kolalambur",Salary=52000 }); 
} 
 
Also we already have a kb to add the new row programmatically, 
Kb Link: 
Regards, 
Jai Ganesh S 


Hello, Syncfusion team!

necessarily must be the source in SfDataGrid?

Thanks!


AZ Azem replied to Azem October 15, 2016 04:16 PM UTC

Hi Azem, 
You can achieve your requirement for adding a new row at rime like  blow, 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
  (this.sfGrid.DataContext as UserInfoViewModel).UserDetails.Add(new UserInfo() { UserId=4001, Name="George", DateofBirth=DateTime.Now, City="Kolalambur",Salary=52000 }); 
} 
 
Also we already have a kb to add the new row programmatically, 
Kb Link: 
Regards, 
Jai Ganesh S 


Hello, Syncfusion team!

necessarily must be the source in SfDataGrid?

Thanks!


I want to programmatically create a rows in SfDataGrid.
creating classes (collections) are not suitable for me (at the moment).




JG Jai Ganesh S Syncfusion Team October 17, 2016 11:44 AM UTC

Hi Azem,  
We cannot understand your requirement clearly. But we suspect that you want to add the new row at run time without using the Collection. This requirement can be achieved in SfCellGrid by inserting the rows at runtime like below, 
 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
   //To insert rows (Param : 5 => insert row index , 2=> number of rows to be inserted) 
   this.cellGrid.Model.InsertRows(5, 2); 
} 
 
 
 
Regards, 
Jai Ganesh S 



AZ Azem replied to Jai Ganesh S October 18, 2016 03:49 PM UTC

Hi Azem,  
We cannot understand your requirement clearly. But we suspect that you want to add the new row at run time without using the Collection. This requirement can be achieved in SfCellGrid by inserting the rows at runtime like below, 
 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
   //To insert rows (Param : 5 => insert row index , 2=> number of rows to be inserted) 
   this.cellGrid.Model.InsertRows(5, 2); 
} 
 
 
 
Regards, 
Jai Ganesh S 


exactly what is needed!

Thanks!


JG Jai Ganesh S Syncfusion Team October 18, 2016 07:14 PM UTC

Hi Azem, 
Thank you for the update. 
Please let us know if you need further assistance on this. 
Regards, 
Jai Ganesh S 


Loader.
Live Chat Icon For mobile
Up arrow icon