日期:2014-05-18 浏览次数:20860 次
private void simpleButton2_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("a", typeof(string)); dt.Columns.Add("b", typeof(string)); dt.Rows.Add("dkf", "dkgj"); dataGridView1.DataSource = dt; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { DataTable dt = dataGridView1.DataSource as DataTable; dt.DefaultView.RowFilter = "a='" + comboBox1.Text + "'"; }
------解决方案--------------------
在你另一篇贴子里我只是说要那样写,想不到你直接用了,要换成你实际的列名啊
------解决方案--------------------
DataTable dt = dataGridView1.DataSource as DataTable();
这样直接赋值得到的dt有问题,所以出错