【发布时间】:2012-07-25 05:05:20
【问题描述】:
通过 WinForms 中的 bindingsource 控制使用 Linq to sql,我无法让它工作:
private void textBox1_TextChanged(object sender, EventArgs e)
{
productBindingSource.Filter = string.Format("ProductName LIKE '*{0}*'", textBox1.Text);
MessageBox.Show("Changed");
}
NorthwindDataContext dc;
private void FrmFilter_Load(object sender, EventArgs e)
{
// create new data context
dc = new NorthwindDataContext();
// set the binding source data source to the full order table
var qry = (from p in dc.Products select p).ToList();
this.productBindingSource.DataSource = dc.GetTable<Product>();
}
当我在文本框中键入一些字母时,datagridview 中没有任何反应。 感谢您的建议...
【问题讨论】:
-
您的数据源极不可能有 dataGridViewTextBoxColumn2 列,看起来它属于 DataGridView 列。尝试对您的 datagridview 正在使用的数据源的列进行过滤。
-
试过这个:this.productBindingSource.Filter = string.Format("ProductName like '%{0}%'", textBox1.Text.Trim().Replace( "'", "''"));没有任何改变。
标签: c# winforms linq-to-sql filtering