在練題目的時候
題目說要使用BindSource的條件篩選
但用Filter屬性來寫時發現DataGridView沒有反應
請問是哪邊發生了問題呢?
小弟第一在這裡發問?
請多多指教m(_ _)m
visitEntities1 db = new visitEntities1();
private async void btnImport_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog ()== DialogResult.OK )
{
//匯入JSON檔案資料儲存到資料庫
StreamReader sr = new StreamReader(openFileDialog1.FileName);
景點_ visit;
//Deserialize<T>(string json) 為題目自定義的函式
List<Travel> output = Deserialize<Travel>(sr.ReadToEnd());
foreach (Travel item in output)
{
visit = new 景點_();
visit.交通資訊 = item.交通資訊;
visit.名稱 = item.景點名稱;
visit.地址 = item.地址;
visit.營業時間 = item.營業時間;
visit.說明 = item.景點說明;
db.景點_.Add(visit);
}
db.SaveChanges();
MessageBox.Show("匯入" + db.景點_.Count().ToString() + "筆");
bindingSource1.DataSource = db.景點_.Local;
bindingNavigator1.BindingSource = bindingSource1;
dgvData.DataSource = bindingSource1;
dgvData.AutoGenerateColumns = true;
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
//TODO 查詢畫面顯示景點關鍵字
string search = toolStripTextBox1.Text;
bindingSource1.RemoveFilter();
bindingSource1.Filter="名稱 Like 'search'";
}