Domanda

I am trying to add rows in the datarow one by one..For example first row is of list and second row is of list,then the third row is of list and fourth of list and so on..Here is my code ..

// Declaring a list of datahandling type data which contains
// groupid,stringid,stringtext etc.
List<Data> data = new List<Data>();         
List<Data> diff = new List<Data>();

// Function which separates the relevant data from the string
// and stores it in the list.
control.Stringhandler(readcontents.Contents, ref data);
control.Stringhandler(readcontents.Translated_contents, ref diff);

foreach (var array in data)
{
    datarows.Rows.Add(array.GroupID, array.StringID, array.StringText);
    // datarows.Rows.Add(array.GroupID, array.StringID, array.StringText);
    save = array.Lines + 1;
}

My question is that the foreach() adds data in the datarow,row by row ..I want to add diff row next to data row.. For example the datarow should be added in this way

        datarow.row[0]=data;
        datarow.row[1]=diff;
        datarow.row[2]=data;
        datarow.row[3]=diff;

That is what i am trying to do..

È stato utile?

Soluzione

If both list are of <Data> type, you can concat first two list and then add rows. Like this

var lstCombined = data.Concat(diff)
 foreach (var array in lstCombined )
        {
            datarows.Rows.Add(array.GroupID, array.StringID, array.StringText);
          // datarows.Rows.Add(array.GroupID, array.StringID, array.StringText);
            save = array.Lines + 1;
        }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top