Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to close form with esc key in Datagrid
Message
From
19/11/2006 08:56:20
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
How to close form with esc key in Datagrid
Environment versions
Environment:
C# 1.1
Miscellaneous
Thread ID:
01171053
Message ID:
01171053
Views:
53
When text control in grid is active, esc key does not close form
How to close the form in this case in .NET 1.1 ?

To reproduce:
1. Run the code
2. Click in first row in first column
3. Press esc key

Observed: esc key is ignored

Expected: Esc must close form
using System;
using System.Windows.Forms;

namespace closeissue
{
    public class Form1 : Form
    {
        public Form1()
        {
            this.IsMdiContainer = true;
            this.Load += new System.EventHandler(this.Form1_Load_1);
         }

        private void Form1_Load_1(object sender, EventArgs e)
        {
            Form x =new Form2();
            x.MdiParent = this;
            x.Show();
        }
    }

    public class Form2 : Form
    {
        public Form2()
        {
        dataGrid1=new DataGrid() ;
            this.form1BindingSource = new System.Windows.Forms.BindingSource();
            this.dataGrid1.DataMember = "";
            this.dataGrid1.DataSource = this.form1BindingSource;
            this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.form1BindingSource.DataSource = typeof(createdobjectstotshown.Form1);
            this.Controls.Add(this.dataGrid1);
            this.KeyPreview = true;
            this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form2_KeyPress);
        }
        private System.Windows.Forms.DataGrid dataGrid1;
        private System.Windows.Forms.BindingSource form1BindingSource;
        private void Form2_KeyPress(object sender, KeyPressEventArgs e)
        {
            Close();
        }
    }

    static class Program
    {
        static void Main()
        {
            Application.Run(new Form1());
        } }   }
Andrus
Next
Reply
Map
View

Click here to load this message in the networking platform