Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I am working on GUI form .I want to use a button to display a table which is in database through data grid view.The button name is display and i want when i click on this display button the whole table will appear through data grid view.
I applied the below coding for that but error occured on
if (e.Keychar == (char)13 and the error is:-

'System.EventArgs' does not contain a definition for 'Keychar' and no extension method 'Keychar' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?).




private void btndisplay_Click(object sender, EventArgs e)
{
if (e.Keychar == (char)13) {
string strSQLconnection = "Data Source=AKMINDER-PC\SQLEXPRESS;Initial Catalog=elin appliances(Comaker of PHILIPS);Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
SqlCommand sqlCommand = new SqlCommand("SELECT * FROM vendor_info", sqlConnection);
sqlConnection.Open();

SqlDataReader reader = sqlCommand.ExecuteReader();

GridView1.DataSource = reader;
GridView1.DataBind();
GridView1.Visible = true;
GridView1.Focus();
}
Posted
Comments
Sergey Alexandrovich Kryukov 25-Feb-12 23:54pm    
Why do you need this 13? Click is a click, its does not have any particular key.
--SA

1 solution

Try using:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode.ToString() == "Return")
    {
        //write here what you want
    }
}

Put it in key down event,This is in case of Enter key pressed
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Feb-12 23:53pm    
Very, very bad!
The comparison should be (e.KeyCode == Keys.Return).
Besides, it does not solve a problem. Why checking for the key at all? OP works with a button (!).
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900