Hi.
Follow this Steps:
create new application in c#.net
place 1 combobox and 1 textbox on form
on PreviewKeyDown Event for combobox write a code also for text box
now run the application and set focus to combobox and press any key!
the code you typed run 2 times!! but for textbox run only 1 times!
very thanx
exeuse me for bad english!
Loading

Dushan Stankovic72 reputationPosted Oct 2, 2009, 11:00 AM EDT
When you set DropDownStyle property to DropDownList this event occurs only one time, but if you set other two value to DropDownStyle prop event occurs two times.
I think that is event is raised first time for keyboard key pressed and second time for printing pressed key at text field.
I didn't find any different answer on the web.
This example is for debug purpose only:
private void comboBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder(); messageBoxCS.AppendFormat("{0} = {1}", "Alt", e.Alt); messageBoxCS.AppendLine(); messageBoxCS.AppendFormat("{0} = {1}", "Control", e.Control); messageBoxCS.AppendLine(); messageBoxCS.AppendFormat("{0} = {1}", "KeyCode", e.KeyCode); messageBoxCS.AppendLine(); messageBoxCS.AppendFormat("{0} = {1}", "KeyValue", e.KeyValue); messageBoxCS.AppendLine(); messageBoxCS.AppendFormat("{0} = {1}", "KeyData", e.KeyData); messageBoxCS.AppendLine(); messageBoxCS.AppendFormat("{0} = {1}", "Modifiers", e.Modifiers); messageBoxCS.AppendLine(); messageBoxCS.AppendFormat("{0} = {1}", "Shift", e.Shift); messageBoxCS.AppendLine(); messageBoxCS.AppendFormat("{0} = {1}", "IsInputKey", e.IsInputKey); messageBoxCS.AppendLine(); MessageBox.Show(messageBoxCS.ToString(), "PreviewKeyDown Event"); }Master BillaRank #2,229 · 630 reputationPosted Oct 2, 2009, 10:17 PM EDT
This is occur before the key down event.So you can write like this way to move your combo box
Here is to
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.previewkeydown.aspx
thank you
ali gholami3 reputationPosted Oct 3, 2009, 9:28 PM EDT
but i want to handle key down event until my code in previewkeydown event run one time and pressed key no writen to combobox,
for example when i press Ctrl+S on combobox, saveButton click event occure one time and "s" no writen to combobox.
exeuse me for bad english!