Recently working on one of my application using Linq, I need to fill the datagridview with selected rows and columns which i can get from querying a list of objects using Linq. Now for every result i need to add an additional static record to the grid view. for this i need to have this record as a last record for my selected IQueryable variable from LINQ result. Let me show you through example what I said till now…
Ex:
1.
var varresult = from r
in
lstobject select
new
{ COLUMN1 = r.Title, COLUMN2 = r.Price };
2.
3.
DataGridView1.datasource = varresult ;
4.
5.
DataGridView1.databind();
Now I need to add a new static record (i.e.., new{COLUMN1=”Discount Price”, COLUMN2=10}) to the existing varresult object…
varresult = varresult.ToList().Union(
[] {
{COLUMN1=”Discount Price”, COLUMN2=10}});
thats it Now a last record will be what you want… Please note that the variables and there types should be same as result object had.
Hope this Helps u…
Happy Coding
Maheshkumar S Tiwari edited Original. Comment: Added tags and minor edit