sfDatagrid to Object list in c#
I create data source Based on the list of objectsa and add it to sfdatagrid
sample class:
public class temp
{
public int ID { get; set; }
public string Value{ get; set; }
public bool Akt{ get; set; }
}
next add new row to datagrid and edit other
My question is how to read values from datagrid to new list of object (class temp)?
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
VS
Vijayarasan Sivanandham
Syncfusion Team
July 17, 2020 06:02 PM UTC
Hi Artur Kolodziej,
Thank you for contacting Syncfusion support.
Based on provided information your requirement can be achieved by getting data by using view records collection of SfDataGrid and converting into list. Please refer the below code snippet,
Thank you for contacting Syncfusion support.
Based on provided information your requirement can be achieved by getting data by using view records collection of SfDataGrid and converting into list. Please refer the below code snippet,
|
var records = SfDataGrid.View.Records;
foreach(var record in records)
{
var rowdata= record.Data;
} |
We hope this helps. Please let us know, if you require further assistance on this.
Regards,
Vijayarasan S
Marked as answer
AK
Artur Kolodziej
July 18, 2020 09:25 PM UTC
Hi Vijayarasan Sivanandham,
Thanks for reply,
the code below worked. But is it correct?
first:
List<temp> Foo = new List<temp>();
SfDataGrid.DataSource = Foo;
next i read...
List<temp> tmpFoo = new List<temp>();
var records = SfDataGrid.View.Records;
foreach (var record in records)
{
temp dataRowView = new temp();
dataRowView = record.Data as temp ;
tmpFoo.Add(dataRowView);
}
VS
Vijayarasan Sivanandham
Syncfusion Team
July 20, 2020 11:56 AM UTC
Hi Artur Kolodziej,
Thanks for the update.
Yes, In your provided code snippet as correct way to read the data as list in SfDataGrid.
Regards,
Vijayarasan S
Thanks for the update.
Yes, In your provided code snippet as correct way to read the data as list in SfDataGrid.
Regards,
Vijayarasan S
GI
Giovanni
July 22, 2021 09:35 PM UTC
Hi
You can also do it with LINQ
List<objectClass> listObject= SfDataGrid .View.Records.Select(x=> x.Data as objectClass ).ToList();
Just one line.
VS
Vijayarasan Sivanandham
Syncfusion Team
July 23, 2021 11:41 AM UTC
Hi Giovanni,
Thanks for the update.
Regards,
Thanks for the update.
Regards,
Vijayarasan S
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
- Marked answer
-
AK Artur Kolodziej
- Jul 16, 2020 11:02 PM UTC
- Jul 23, 2021 11:41 AM UTC