Assuming that gridcontrol is binded with data source, such as
DataTable
, you can use Linq to get expected result:
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("rno", typeof(int)));
dt.Columns.Add(new DataColumn("Emp code", typeof(int)));
dt.Columns.Add(new DataColumn("d1", typeof(string)));
dt.Columns.Add(new DataColumn("d2", typeof(string)));
dt.Columns.Add(new DataColumn("d3", typeof(string)));
dt.Columns.Add(new DataColumn("d4", typeof(string)));
dt.Columns.Add(new DataColumn("d5", typeof(string)));
dt.Rows.Add(new object[]{1, 101, "P", "P", "A", "A", "P"});
dt.Rows.Add(new object[]{2, 102, "A", "A", "A", "A", "P"});
dt.Rows.Add(new object[]{3, 103, "P", "A", "P", "A", "P"});
var resultset = dt.AsEnumerable()
.Select(r => new
{
rno = r.Field<int>("rno"),
EmpCode = r.Field<int>("Emp code"),
d1 = r.Field<string>("d1"),
d2 = r.Field<string>("d2"),
d3 = r.Field<string>("d3"),
d4 = r.Field<string>("d4"),
d5 = r.Field<string>("d5"),
TotalP = new List<string>(){r.Field<string>("d1"), r.Field<string>("d2"), r.Field<string>("d3"), r.Field<string>("d4"), r.Field<string>("d5")}
.Count(x=>(string)x=="P"),
TotalA = new List<string>(){r.Field<string>("d1"), r.Field<string>("d2"), r.Field<string>("d3"), r.Field<string>("d4"), r.Field<string>("d5")}
.Count(x=>(string)x=="A")
});
Finally, you can convert linq query into DataTable object:
Creating a DataTable From a Query (LINQ to DataSet) | Microsoft Docs[
^]
Good luck!