why i can't edit anything in my DataGridView?

47 views Asked by At

I got this problem. I have a DataGridView with a DataSource that is a Linq query, and when I show the data from my database in the DataGridView, I can't edit anything.

What's the problem?

Here's my code.

private void btMau_Click(object sender, EventArgs e)
{
        var lst = from list in db.Maus
                  join dt in db.DiaTangs on list.IDDiaTang equals dt.IDDiaTang
            select new
            {
                list.IDMau,
                list.IDHoKhoan,
                list.Lop,
                list.BeDayMau,
                list.DoSauMau,
                dt.TenDiaTang,
                dt.MoTa
            };
        dgv.DataSource = lst;
        dgv.ContextMenuStrip = contextMenuStrip2;
        check = "Mau";
}

Sorry for my bad english!

PS: dgv is DataGridView

1

There are 1 answers

0
Yuri On

currently your variable is read only. You can fix it by

var lst = (from list in db.Maus
              join dt in db.DiaTangs on list.IDDiaTang equals dt.IDDiaTang
        select new
        {
            list.IDMau,
            list.IDHoKhoan,
            list.Lop,
            list.BeDayMau,
            list.DoSauMau,
            dt.TenDiaTang,
            dt.MoTa
        }).ToList();

For more details and example, please see this page