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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -