[英]I need to filter my DataGridView with selected column
我正在开发一个带有Windows
Forms
的通用SQLManipulator
。 我需要Filter
我的columns
但我不知道如何转换:
private void AdvancedDataGridView_FilterStringChanged(object sender, EventArgs e)
{
this.customerBindingSource.Sort = this.advancedDataGridView.SortStrings;
}
那不是我从那个教程中看到的代码。 我的应用程序未与 DB 连接。 我有登录表单,当您输入服务器名称时,您会得到一个带有数据库名称的combobox
,然后您将转到下一个表单,在此处选择table
,然后填充datagridview
。
这就是我的表单的样子: 但是每次列都会有不同的名称? 我不确定我应该在这里做什么?
我是否需要转换customerBindingSource
,或者我应该做其他事情?
我可以通过使用BindingSource来做到这一点
过滤列
private void AdvancedDataGridView_FilterStringChanged(object sender, EventArgs e)
{
try
{
BindingSource source1 = new BindingSource();
source1.DataSource = AdvancedDataGridView.DataSource;
AdvancedDataGridView.DataSource = source1;
source1.Filter = AdvancedDataGridView.FilterString;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
排序列
private void AdvancedDataGridView_SortStringChanged(object sender, EventArgs e)
{
try
{
BindingSource source1 = new BindingSource();
source1.DataSource = AdvancedDataGridView.DataSource;
AdvancedDataGridView.DataSource = source1;
source1.Sort = AdvancedDataGridView.SortString;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
希望它有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.