Nevron Forum

What is the equivalent for System.Windows.Forms.KeyPressEventArgs in Nevron's Winforms?

https://www.nevron.com/Forum/Topic3901.aspx

By Fábio Mello - Wednesday, July 28, 2010

I'm using a Nevron.UI.WinForm.Controls.NComboBox but it seems there is no keypress event for it.
By Nevron Support - Thursday, July 29, 2010

Hello Fabio,

NComboBox has KeyPress even should work properly, only the arrow keys are not handled as it is in the standard .NET ComboBox control.

By Fábio Mello - Thursday, July 29, 2010

Thanks for the fast response, but the KeyPressEventHandler from System.Windows.Forms does not work with the Nevron.UI.WinForm.Controls.NComboBox, right? I would like to know if there is this kind of handler in Nevron.UI. If there is, please post the path to that handler; if not, what should I do (the code for it) to deal with the KeyPressEvent?

obs: myNComboBox.Editable = true; //it is necessary because the text is typed inside the text area
By Nevron Support - Friday, July 30, 2010

Hello Fabio,

When Editable property is set to true you should attach to NComboBox.EditControl.KeyPress event.

 

 

By Fábio Mello - Sunday, August 1, 2010

It still doesn't work. This is the code:

private void InitializeComponent()
{
...#1
this.myForm.EditControl.KeyPress += new KeyPressEventHandler(this.EditControl_KeyPress);/*this is the wrong line*/
...
}

private void EditControl_KeyPress(object sender, KeyPressEventArgs e)
{
... do something;
}

What I am asking is: is this "KeyPressEventArgs" from "System.Windows.Forms" the proper event handler for Nevron.UI.WinForm.Controls.NComboBox? If not, what and where is the event handler? If it is, why there is a NullReferenceException in #1?

No error occurs when I use the System.Windows.Forms.Combobox, but I wanted to use the NCombobox.
By Nevron Support - Monday, August 2, 2010

Hello Fabio,

You should attach to NComboBox.EditControl.KeyPress only when Editable property is true. The EditControl is actually a text box that represents the editable part of the combo box. When Editable is false EditControl will be null and you should be attached to NComboBox.KeyPress.

KeyPressEventArgs is the proper event argument for KeyPressEventHandler.

Basically you should do the following:

if (nComboBox1.EditControl != null)
{
    nComboBox1.EditControl.KeyPress +=
new KeyPressEventHandler(EditControl_KeyPress);
}
else
{
    nComboBox1.KeyPress +=
new KeyPressEventHandler(nComboBox1_KeyPress);
}

...

void nComboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    DoSomething(sender, e);
}

void EditControl_KeyPress(object sender, KeyPressEventArgs e)
{
    DoSomething(sender, e);
}

private void DoSomething(object sender, KeyPressEventArgs e)
{
   //Do Something.
}

By Fábio Mello - Wednesday, August 4, 2010

Thank you