Instead of overwriting newRow["LongDescription"]
, just concatenate the values:
if (drText.ItemArray[2].ToString() == "2")
{
newRow["LongDescription"] += Regex.Replace(drText.ItemArray[1].ToString(), "<.+?>", string.Empty);
}
Or, if you want some kind of seperator:
if (drText.ItemArray[2].ToString() == "2")
{
newRow["LongDescription"] = newRow["LongDescription"] +
(String.IsNullOrWhiteSpace(r.Field<string>(4)) ? "" : "\n") +
Regex.Replace(drText.ItemArray[1].ToString(), "<.+?>", string.Empty);
}
Or, since you're already using Linq:
// assuming there's always a single row with ID == 0 and one with ID == 1
var result = dtTextslike.AsEnumerable()
.GroupBy(row => row["varenummer"])
.Select(grp => new object[]
{
grp.Key,
grp.First()["brand"],
grp.Single(r => r.Field<int>("ID") == 0)["text"],
grp.Single(r => r.Field<int>("ID") == 1)["text"],
String.Join("\n", grp.Where(r => r.Field<int>("ID") == 2)
.OrderByDescending(r => r.Field<int>("LineNumber"))
.Select(r => r.Field<string>("text")))
});
foreach(var line in result)
dtFinal.Rows.Add(line);