我目前只有一个搜索工作在1列。我想在搜索中添加多个列。所以我可以搜索Student_FName,Student_SName和Student_Email
以下是我目前正在使用的代码。我需要在其中添加OR语句吗?或者是否存在包含多个行过滤器的另一种方法
private void SearchTxt_TextChanged(object sender, EventArgs e)
{
try
{
var bindData = (BindingSource)studentGridView.DataSource;
var dataTable = (DataTable)bindData.DataSource;
dataTable.DefaultView.RowFilter = string.Format("Student_Username LIKE '%{0}%'", SearchTxt.Text );
studentGridView.Refresh();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 0 :(得分:1)
使用从数据表中选择
private void SearchTxt_TextChanged(object sender, EventArgs e)
{
try
{
var bindData = (BindingSource)studentGridView.DataSource;
var dataTable = (DataTable)bindData.DataSource;
var rows = dataTable.Select (string.Format("Student_Username LIKE '%{0}%' AND [Some other filter]", SearchTxt.Text ));
studentGridView.DataSource = rows.CopyToDataTable()
studentGridView.Refresh();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 1 :(得分:0)
private void SearchTxt_TextChanged(object sender, EventArgs e)
{
try
{
var bindData = (BindingSource)studentGridView.DataSource;
var dataTable = (DataTable)bindData.DataSource;
dataTable.DefaultView.RowFilter = string.Format("Student_Username LIKE '%{0}%' OR Student_FName LIKE '%{0}%'", SearchTxt.Text );
studentGridView.Refresh();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 2 :(得分:0)
dict.values