store group ids from sfdatagrid into strings

hi there,

I have the following datatable from sfdatagrid,

Color           ID

Red              1
Red              2
Yellow         3
Orange         4
Orange         5
Orange         6

I want to store the ids in 3 different string Red, Yellow and Orange. Expected output should be
Red=1,2
Yellow=3
Orange=4,5,6

how can I achieve this using clicking the button?


1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team July 30, 2020 02:32 PM UTC

Hi Mark Jayvee,

Thank you for contacting Syncfusion support.

Based on provided information we have prepared the sample for achieve your requirement. Please refer the below code snippet,
 
private void button1_Click(object sender, EventArgs e) 
{ 
            List<string> Red = new List<string>(); 
            List<string> Yellow = new List<string>(); 
            List<string> Orange = new List<string>(); 
            var records= this.sfDataGrid1.View.Records; 
            foreach (var record in records) 
            { 
                var data = record.Data as DataRowView; 
                var color = data.Row["Color"].ToString(); 
                if (color == "Red")                 
                    Red.Add(data.Row["Ids"].ToString());                 
                else if (color == "Yellow")                 
                    Yellow.Add(data.Row["Ids"].ToString());                 
                else if (color == "Orange")                 
                    Orange.Add(data.Row["Ids"].ToString());                                
            } 
             
            txtDisplayString.Text = "Red="+string.Join(",", Red) + "\t\t"+ "Yellow=" + string.Join(",", Yellow) + "\t\t" + "Orange=" + string.Join(",", Orange); 
} 
 
We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S
 


Marked as answer
Loader.
Up arrow icon