Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

How to associate the result of a LINQ query with the dataSource of a dataGridView

Hello everybody,

I have a dataGridView with the result of a query, this dataGridView allows me to select the records I want:

Code
private void button1_Click(object sender, EventArgs e)
{

    var values =
        from DataGridViewRow row in ewgrid1.Rows
        where Convert.ToBoolean(row.Cells["colCheck"].Value) == true
        select new {id = row.Cells[1],name=row.Cells[2] };

    frmResult formResultat = new frmResult();
    formResultat.data = values.ToList();
    
    formResultat.Show();

}

The idea is to associate the result of this query in the grid of the frmResult form, but I don't know with what type of data to collect and associate it to the dataSource of the dataGridView.

The frmResult:
Code
public partial class frmResult : Form
    {
        public object data { get; set; }
        public frmResult()
        {
            InitializeComponent();
        }

        private void frmResult_Load(object sender, EventArgs e)
        {
            ewgrid1.DataSource = data;
        }
    }

Waiting for the result of the Select as a generic object type as it is in the code is the closest I've ever been to working, but I don't know what data type to put the result in to make it work.

Can you please help me?


Regards and thanks
Can't you just set the RowFilter to something like-

Code
dataView.RowFilter = "colCheck = true";

Instead of building out that linq query?
nameless


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Jake JohnsonDec 10, 2020 09:25 AM 3 304 Dec 10, 2020 09:25 AM
Last Post: Xamarin
[C#] by SouthSide1990Nov 16, 2020 05:48 PM 0 219 Nov 16, 2020 05:48 PM
Last Post: SouthSide1990
[.NET] by Takehito MorokuzuJun 9, 2019 03:51 PM 2 219 Jun 9, 2019 03:51 PM
Last Post: Hawk HF