Should not close the Menu of ToolStripCombobox - c#

Avoid the closing of Menu in the ToolStripCombobox in the Windows application. when i select the items of the combo by using the UP/Down arrow keys the dropdown menu is closed automatically whenever the selection changed. How to avoid that auto closing?

I cannot reproduce this.
I created a form, added a ToolStrip control to it with some standard items, and then added a ToolStripComboBox to the end. Finally, I added a few items to the combo box for testing purposes.
When I run the application, and toggle the selected item in the combo box using the up/down arrow keys, the combo box does not close automatically. I can move the selection up and down the items in the combo box without ever triggering it to close until I press the Enter key.
What are we doing differently? Please update your question to explain the steps necessary to reproduce the behavior that you describe.

Related

WPF Prevent button from taking focus from any other control

I have an "On screen keypad" with some up/down/left/right/select buttons.
The select button is effectively a click and the arrow keys fire the associated up/down/left/right key.
The problem is that when selecting a combo box, I can't press the down/up buttons to navigate the items in the list. It is because the combo box auto closes when loosing focus. I can see similar problems happening with other controls, so I would like to see if there is a way to do the following.
For certain buttons (up/down/etc), when clicked, fire the click event, but don't take focus from w/e currently has the focus. This would allow the combox dropdown to stay open while pressing up/down to navigate through the items.
I have tried to set Focusable=False on the navigation buttons but the focus is still taken away from the combo box and the dropdown closes.
Any ideas/suggestions?
Thanks in advance
This isn't happening because of anything your Buttons are doing so changing their focus state won't make any difference. ComboBoxes close when you click anywhere outside of them, including empty space, non-interactive controls, other windows...

How to prevent menu (ContextMenuStrip) to steal focus from my TextBox control?

I am trying to replicate an intellisense like feature where you have a textbox and a menu that's shown below it. I know intellisense doesn't use ContextMenuStrip, but my version has to have categories which are sub-menu items.
So as soon as the user clicks into my TextBox, I bring up the menu below once, but then even though I can see the caret in my TextBox it doesn't receive any key inputs. I have to click inside the TextBox again but that removes the menu from the screen.
Is there a way to prevent this? Or perhaps make the menu persistent on the screen without stealing focus?
ToolStrip control with items added to it seems to work since it's always on the form.

C# / WinForms: Highlight only the first item of a ListBox on drag & drop

In a ListBox: User should be able to pick multiple items by holding the CTRL key and seleting them. I have this working, but this ListBox needs to be able to do drag & drop of its items to another ListBox as well. Now, when it comes to drag & drop, if the user holds down the left button of the mouse and continue scrolling down or up with it, it selects all other items that are moused over, but I do not want this. When the user holds down the left button to move the item by drag & drop I want him to just be able to pick that item and all other items should not be selected.
It sounds like your ListBox's SelectionMode property is set to MultiExtended. Setting this to MultiSimple should solve the problem.

How to enable paste using CTRL+V in empty listbox?

I have an empty listbox which I would like to allow the user to paste items into. Currently I make sure the listbox has focus (as per WPF: How to enable a Command?) when the user clicks on it. Then if they right-click the context menu which contains the Paste command will be enabled and can be clicked which is excellent. However if instead of right-clicking the user presses CTRL+V on the keyboard the Paste command does not execute.
So far I can't figure out how to make this work. If the listbox has items in it and one of them is selected everything works fine.
Thanks
Add your own CommandBinding for the Paste-Command to the ListBox.
m_yourlistBoxReference.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste,YourExecutedHandler,YourCanExecuteHandler));
However, such as you already wrote, you have to ensure that the ListBox is focused, otherwise the CommandBinding will not execute. To ensure this, you can register to the PreviewMouseDown-event and focus the ListBox if not already IsFocused is true.
I'm not a WPF expert; however, in WinForms the easiest way is to add a context menu with the short-cut keys for Cut, Copy, Paste, etc. Then you don't have to do anything but implement the context menu click.

How to move items in combo box using keyboard keys?

Ex:
Combo box1:
Thanks Up and down arrow keys works when combo box has its focus.
But how can i use characters to select items on combo box.
Ex: Apple,Banana,Orange are the items on combo box
and when i got focus on it and i press A key on keyboard Combo box item will display Apple.
Winforms..
Assuming WinForms, this is the default behavior when the ComboBox has focus.
If you're not clicking on the ComboBox, you're going to have to do something about it:
Listen for the MouseEnter event and set focus on the ComboBox.
Or, use Key Preview, listen for the q, Up, and Down keys, check the mouse position, and act accordingly.

Categories

Resources