[英]Counting filled rows issue in datagridview using binding source in C#
我正在使用Json用BindingSource方法填充DataGridView。 隨着我的前進,我想知道為什么當根據我的where語句沒有選擇任何值時,行數為什么仍然為1。 請幫我。
這是我的示例代碼:
public void JsonPopulateDGV(string JsonDir, int partsId, string fileName)
{
string json = File.ReadAllText(JsonDir);
var jSectionCollection = JsonConvert.DeserializeObject<JSectionCollection>(json) ?? new JSectionCollection();
BindingSource src = new BindingSource();
src.DataSource = jSectionCollection.JSections.Where(x => x.PartsId == partsId).Where(s=>s.FileDir == fileName);
dataGridSections.DataSource = src;
Console.WriteLine(src.Count);
}
您需要通過調用ToArray
或ToList
執行Where
。 您還可以將兩個where語句合並為一個:
src.DataSource = jSectionCollection.JSections
.Where(x => x.PartsId == partsId && x.FileDir == fileName)
.ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.