Search for value in DataGridView in a column

前端 未结 6 1448
名媛妹妹
名媛妹妹 2020-12-01 17:12

I want the user to be able to search for a number in a column in the DataGridView (dgv). The dgv can hold many records. Each record has a Project Number. So I want the user

6条回答
  •  余生分开走
    2020-12-01 17:56

    "MyTable".DefaultView.RowFilter = " LIKE '%" + textBox1.Text + "%'"; this.dataGridView1.DataSource = "MyTable".DefaultView;

    How about the relation to the database connections and the Datatable? And how should i set the DefaultView correct?

    I use this code to get the data out:

    con = new System.Data.SqlServerCe.SqlCeConnection();
    con.ConnectionString = "Data Source=C:\\Users\\mhadj\\Documents\\Visual Studio 2015\\Projects\\data_base_test_2\\Sample.sdf";
    con.Open();
    
    DataTable dt = new DataTable();
    
    adapt = new System.Data.SqlServerCe.SqlCeDataAdapter("select * from tbl_Record", con);        
    adapt.Fill(dt);        
    dataGridView1.DataSource = dt;
    con.Close();
    

提交回复
热议问题