Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

how to show or not show the DataGridView by KeyPress and query

$
0
0

hi

i work under the KeyPress event and fill DataGridView in Data like this:

  private void txtLookName_KeyPress(object sender, KeyPressEventArgs e)
        {
            SQL = "select id,aname from sq_table where aname like '%" + txtLookName.Text.Trim() + "%'";
            dsView = new DataSet();
            adp = new OleDbDataAdapter(SQL, Main.Conn);
            adp.Fill(dsView, "sq_table");
            adp.Dispose();
            if (dsView.Tables["sq_table"].Rows.Count == 0)
            {
                dataGridView1.Visible = false;
                return;
            }
            else
            {
                dataGridView1.Visible = true;
            }
            dataGridView1.DataSource = dsView.Tables["sq_table"].DefaultView;
        }

but even if the txtLookName is empty or i got 0 rows i see the DataGridView

how to fix it ?


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>