在编辑DataGridView中的单元格时遇到问题。
当我从LINQ检索数据时,我在ReadOnly中将其设置为false。
public class Cumst
{
public string Month { get; set; }
public double Quantity { get; set; }
}
我的Linq查询:
var juxtaPos = (from test21 in repos.GetTable<Lesson_21>()
where test21.ID == id && test21.Product == "IPHONE"
select (new Cumst
{
Month = test21.Month,
Quantity = Convert.ToDouble(test21.Quantity)
})
).ToList();
dgvJuxtaposition.DataSource = juxtaPos;
当我使用SQL字符串编辑单元接收数据时,启用了...我不知道为什么它不适用于Linq
答案 0 :(得分:0)
使用BindingSource作为数据源,并将带有数据的BindingList分配给BindingSource
请参见Advantages BindingList above List
在构造函数中,可能在InitializeComponent中:
BindingSource bindingSource = new BindingSource();
DataGridView dgv = new DataGridView();
dgv.DataSource = bindingSource;
数据到达时:
void DisplayCumst(IEnumerable<Cumst> cumst)
{
BindingList<Cumst> bindingList = new BindingList(cumst.ToList());
bindingSource.DataSource = bindingList;
}