日期:2014-05-18 浏览次数:20768 次
private void textBox2_TextChanged(object sender, EventArgs e) { DataSet ds = new DataSet(); System.Data.DataTable dt = new System.Data.DataTable(); dt.TableName = "client_info"; ds.Tables.Add(dt); for (int j = 0; j < dataGridView1.Columns.Count; j++) { dt.Columns.Add(dataGridView1.Columns[j].HeaderCell.Value.ToString()); } for (int j = 0; j < dataGridView1.Rows.Count; j++) { DataRow dr = dt.NewRow(); for (int i = 0; i < dataGridView1.Columns.Count; i++) { if (dataGridView1.Rows[j].Cells[i].Value != null) { dr[i] = dataGridView1.Rows[j].Cells[i].Value.ToString(); } else { dr[i] = ""; } } dt.Rows.Add(dr); } ////ds = new DataSet(dt); //以下为过滤代码 DataView dv = new DataView(); dv.Table = ds.Tables["client_info"];//存放楼上的dt dv.RowFilter = "收货地址 like '%" + textBox2.Text + "%' "; dataGridView1.DataSource = dv; }