| | |
Capturing "Enter" key event in C# windows application
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 116
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: May 2006
Posts: 21
Reputation:
Solved Threads: 0
Hey, do you mean something like this?
How does that work?
C# Syntax (Toggle Plain Text)
private void [your data grid name](object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { MessageBox.Show("Enter pressed", "Attention"); } }
How does that work?
+[->,----------]<[+++++++++++.<]
•
•
Join Date: Sep 2006
Posts: 116
Reputation:
Solved Threads: 0
•
•
•
•
Hey, do you mean something like this?
C# Syntax (Toggle Plain Text)
private void [your data grid name](object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { MessageBox.Show("Enter pressed", "Attention"); } }
How does that work?
I got the solution!
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
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)
{
}
}
}
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)
{
}
}
}
![]() |
Similar Threads
- Hidden program installs .dlls with randomly generated names in random "notify" reg. (Viruses, Spyware and other Nasties)
- Trojan Horse - HELP PLEASE (Viruses, Spyware and other Nasties)
- reading a char from keyboard without pressing "Enter"??? (C)
- google "keyword" question (Search Engine Optimization)
- "enter" event (C#)
- why i have to press "enter" twice before getline can read the string... (C++)
- Spyware Removal Help!!! "Lookfor" & god knows what else... (Web Browsers)
Other Threads in the C# Forum
- Previous Thread: Getting an exception "Attempted to read or write protected memory." Why?
- Next Thread: Please Help me on these topics
| Thread Tools | Search this Thread |
.net access algorithm alignment array barchart bitmap box broadcast buttons c# c#gridviewcolumn check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing elevated encryption enum event excel file focus forloop form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml





