[英]display search box for each column of data grid view
I want to create search ability based on text box for each column of grid view in c# winforms
application. 我想基于文本框为c#
winforms
应用程序中的网格视图的每一列创建搜索功能。 How do I enable this after displaying primary data grid view result in order to filter columns based on text for each one. 在显示主数据网格视图结果后如何启用此功能,以便根据每个文本的文本来过滤列。
SqlConnection con = new Sql Connection(@"");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
cmd = new SqlCommand("sp_text_box", con);
con.Open();
cmd.Parameters.Add(new SqlParameter("@ex", combo_Box1.Text));
cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = cmd;
da.Fill(dt);
dataGridView1.DataSource = dt;
}
catch (Exception x)
{
MessageBox.Show(x.GetBaseException().ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cmd.Dispose();
con.Close();
}
First make your dt
variable public by declaring it in a public scope, then try to fill it: 首先通过在公共范围内声明
dt
变量使其成为公共变量,然后尝试填充它:
cmd = new Sql_Command("sp_text_box", con);
con.Open();
cmd_Parameters.Add(new Sql_Parameter("@ex", combo_Box1.Text));
cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = cmd;
da.Fill(dt);
Then filter the data 然后过滤数据
dt.Select("Size >= 230 AND Sex = 'm'")
Pass it to dgv 传递给dgv
dataGridView1.DataSource = dt;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.