我正在尝试将RowFilter应用于DataTable,但是DataTable的问题是,给出了非常规的ColumnNames。就像某个端点在某个端点上,或者其他端点上有空格等等。
作为示例,请考虑以下代码:
public partial class Form1 : Form
{
public Button ClickMe = new Button();
public DataTable TestTable = new DataTable();
public DataGridView TestView = new DataGridView();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Size = new Size(500, 500);
TestView.Size = new Size(300, 300);
ClickMe.Size = new Size(100, 50);
ClickMe.Text = "Click Me!";
ClickMe.Location = new Point(100, 400);
this.Controls.Add(TestView);
this.Controls.Add(ClickMe);
TestView.Visible = true;
TestTable.Columns.Add(new DataColumn("Addressnumb."));
TestTable.Columns.Add(new DataColumn("SecondColumn"));
TestView.DataSource = TestTable;
ClickMe.MouseClick += ClickMe_MouseClick;
for (int i = 0; i < 10; i++)
{
DataRow Row = TestTable.NewRow();
Row["Addressnumb."] = i.ToString();
Row["SecondColumn"] = "Text " + i.ToString();
TestTable.Rows.Add(Row);
}
}
private void ClickMe_MouseClick(object sender, MouseEventArgs e)
{
MessageBox.Show("Filtering for SecondColumn");
TestTable.DefaultView.RowFilter = "SecondColumn LIKE '%1'";
MessageBox.Show("Filtering for Addressnumb.");
TestTable.DefaultView.RowFilter = "Addressnumb. LIKE '%1'";
}
}
有没有一种方法可以逃脱字符或掩盖字符,使RowFilter仍然可以应用?