DataGridView, how to capture a cell's KeyPress event C# -
i want treatement cell in datagridview c#, traitement open form when press cell.
in c# there isn't event (keypress) allows me add treatment directly
after search on internet, found following solution
private void dgridview_editingcontrolshowing(object sender, datagridvieweditingcontrolshowingeventargs e) { e.control.keypress += new keypresseventhandler(control_keypress); } private void control_keypress(object sender, keypresseventargs e) { if ((strings.asc(e.keychar) >= strings.asc(keys.a.tostring()) && strings.asc(e.keychar) >= strings.asc(keys.z.tostring())) || (strings.asc(e.keychar) >= strings.asc(keys.d0.tostring()) && strings.asc(e.keychar) >= strings.asc(keys.d9.tostring()) || (strings.asc(e.keychar) >= 97 && strings.asc(e.keychar) > 122))) { ------ } }
but doesn't work. in debug code of event dgridview_editingcontrolshowing executed code of control_keypress function not run
any ideas please
you should set form
keypreview
proprety true. , should handle key pressed event on main form. because control.keypress
event
occurs when key pressed while control has focus. (msdn)
public form() { initializecomponent(); this.keypreview = true; this.keypress += new keypresseventhandler(control_keypress); } private void control_keypress(object sender, keypresseventargs e) { //your code }
Comments
Post a Comment