Capturing "Enter" key event in C# windows application

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 116
Reputation: bhavna_816 is an unknown quantity at this point 
Solved Threads: 0
bhavna_816 bhavna_816 is offline Offline
Junior Poster

Capturing "Enter" key event in C# windows application

 
0
  #1
Mar 8th, 2007
I have created an aplication in C# windows application version 1.1 to display some records in a datagrid.
The datasource of the datagrid is datatable and not any database.I want tht when we edit any cell of a particular column
and press "Enter" it should show a Message Box let's say "the cell is edited."
I wrote this but its not working
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue.ToString()=="Enter")
{
// When the user presses both the 'Alt' key and 'F' key,
// KeyPreview is set to False, and a message appears.
// This message is only displayed when KeyPreview is set to True.
this.KeyPreview = false;
MessageBox.Show("KeyPreview is True, and this is from the FORM.");
}
}
Can anybody have any idea?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 21
Reputation: covertx is an unknown quantity at this point 
Solved Threads: 0
covertx covertx is offline Offline
Newbie Poster

Re: Capturing "Enter" key event in C# windows application

 
0
  #2
Mar 8th, 2007
Hey, do you mean something like this?

  1. private void [your data grid name](object sender, KeyPressEventArgs e)
  2. {
  3. if (e.KeyChar == 13)
  4. {
  5. MessageBox.Show("Enter pressed", "Attention");
  6. }
  7. }

How does that work?
+[->,----------]<[+++++++++++.<]
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 116
Reputation: bhavna_816 is an unknown quantity at this point 
Solved Threads: 0
bhavna_816 bhavna_816 is offline Offline
Junior Poster

Re: Capturing "Enter" key event in C# windows application

 
0
  #3
Mar 8th, 2007
Originally Posted by covertx View Post
Hey, do you mean something like this?

  1. private void [your data grid name](object sender, KeyPressEventArgs e)
  2. {
  3. if (e.KeyChar == 13)
  4. {
  5. MessageBox.Show("Enter pressed", "Attention");
  6. }
  7. }

How does that work?
thanks for helping !
I got the solution!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: PARAS PATEL is an unknown quantity at this point 
Solved Threads: 0
PARAS PATEL PARAS PATEL is offline Offline
Newbie Poster

enter event

 
0
  #4
Oct 13th, 2009
I Have 2 text box and I am enter the first numbers and then press enter go to next textbox this event I want. . . . . . . . . . .

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.KeyDown += new eventHandler(textBox1_KeyPress);
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Keys.Enter) textBox2.Focus();

}

private void textBox1_Enter(object sender, EventArgs e)
{


}
}
}
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC