As you now the user can select an item from the comboBox by keyboard directly. By mouse I block the user to select some items depending on the behind object state. What's the best solution to stop this when the user uses the keyboard?
A:
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}
With this you can cancel all KB actions on ur ComboBox.
Asssemptions: WinForms
nils_gate
2009-03-16 07:55:31
By that same logic, I contend that your example is too wide in scope. Notice that the OP says "I block the user to select **some items**"
Cerebrus
2009-03-16 11:04:34
My pardon for the comment then :)
nils_gate
2009-03-16 11:34:41
A:
Putting aside the usability issues arising from this sort of requirement (many users are in the habit of using the keyboard and would find it non-intuitive), you could simply handle the KeyDown
event and set KeyEventArgs.Cancel
to True.
private void myCombo_KeyDown(object sender, KeyEventArgs e)
{
// Cancel the event if Up or Down keys are pressed.
if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up))
e.Handled = true;
}
Edit: Clarification before I get downvoted again - This is an example which illustrates the method. It is upto the OP to decide what keys he/she wants to disallow. ^ ^
Cerebrus
2009-03-16 07:58:28
A:
Would please share your decision with me, i really m looking for such decision.
I appreciate your fast reply!
emwedish
2010-07-04 18:41:40