C# PropertyGrid DoubleClick event capture - c#

For a project I am working on, I have some values in a PropertyGrid that are many lines long. I want the user to be able to double-click a value in the grid, which will bring up my custom UI window. I already have it set up so that the UI works when the [...] button is clicked, but I also need it to show up directly if any grid item is double-clicked.
On a side note, looping through the controls of the PropertyGrid and assigning Click/Mouse events to them allows this to happen when the property name is clicked, but still does not capture the click when the property value is clicked. Any suggestions?

Related

TextBox receiving focus when clicking on ListView

I'm struggling to make a custom autocomplete style control for my application using a list view. In one form, the custom control is working as expected, however in another, when clicking on the ListView, rather than the ListViewItem being selected, the first TextBox in the form is selected instead.
Rather than clog up the question with a wall of code, here is the code for the AutoCompleteListView.
Here is an image of the form. Items are redacted due to data protection:
Also, here is a .gif showing the behaviour of the form. What I'm doing in the aformentioned gif is attempting to click on the first item within the ListView, however, as I do that, focus changes to the first text box in the form. This same behaviour occurs when clicking on any item, in any of the 3 text boxes.
I have attempted to trace the events using RuntimeFlow to watch as events fire, but it has not provided any clarity as to what is actually happening. If anyone could point me in the right direction, that'd be greatly appreciated.
My first guess is in ItemClick you are setting visibility to false, which means something else in the form needs focus, ie the textbox. So do a textbox.focus() in ItemClick to the desired textbox. And given that you will not have access to the parent form in this class, I recommend you make an OnClose event in the AutoCompleteListView and subscribe to it in the parent form, to set the focus to somewhere.

How to explicitly set a Control's Event order

I have a listbox which I have used as an autocomplete list in my C# windows application, which has events like MouseClick and Leave.
On MouseClick, I want to set the selected value to a textbox.
On Leave, I want to hide the listbox
Now, the problem is, when I click on a value in listbox, the leave event is fired and listbox gets hidden without setting the value. If I unset the leave event, things work as expected.
NOTE: The purpose of Leave event is to only hide the listbox when some other control is clicked. The autocomplete textbox is implemented using this reference: WinForms | C# | AutoComplete in the Middle of a Textbox?

How to get the clicked event of a wpf data grid?

I have a DataGrid with programmaticaly added rows (items) by adding an ItemSource.
I do not want the user to edit the cells so I set IsReadOnly = true;.
But I want them to click on cells and output which cell was clicked.
I was searching for a Clicked event and was surprised there is no such event for a DataGrid. I want a behaviour like buttons where it doesn't matter if it's clicked by the mouse, space bar, enter or whatever else the system accepts as a "Click".
So how can I achieve that?
Whatever is in the cell template (TextBlock, for instance) could be styled to handle the PreviewMouseUp event and pull the information you want from the control or bound object. The click event is specific to Button, TextBox and other controls that deal with mouse capture. Here is a link that discusses the dilemma you are facing: http://blog.scottlogic.com/2008/12/02/wpf-datagrid-detecting-clicked-cell-and-row.html. He provides examples on how to accomplish the task at hand.

WPF: How do I handle mouse click on a Listview inside of a Button?

I have a listview for displaying a table inside of a button. I have a click event assigned to the button, but when the user clicks on the list view, a row is selected on the list view and the mouse click is never bubbled up to the button.
I'm stuck at this point, and need a way to solve this. All the examples I've seen online are for placing a button inside the listview. How do I make this work?
Set the IsHitTestVisible property to false on your ListView. Since it is a control that normally processes click events, doing this will have it ignore them.
If you don't want the items to be selectable in the first place, you could make the List View unable to receive Focus. Just set the Focusable property to false.
With the List View unable to receive focus, then I would expect the mouse event to bubble up to the button.

How does a ComboBox capture mouse when it is dropped-down?

I am trying to model the behavior of a ComboBox dropdown (or other drop downs for that matter, including context menus) where the drop down closes when you click anywhere else, even on something that can't be focused.
I've tried subscribing for events such as MouseCaptureChanged, LostFocus, and Leave. I have a custom UserControl which is acting as a dropdown and I just want to close it up when the user clicks anywhere else.
This seems like something that's done in many controls so I'd be surprised if there wasn't a simple way to do it.
So far the overcomplicated methods I can come up with to do this are using pinvoke and the SetCapture() function, or to create a MessageFilter. If these are the only options I am not sure which is better.
The ComboBox is constructed from 2 controls.
Base - visible when not active (Control)
DropDownList - visible during edit mode or list selection mode (Window or Form)
Normally the Base is visible. When the user clicks onto the ComboBox, the Base control hides and the DropDownList control shows up. This switch is done on the background, so for the user it seems the control just expanded.
The event you want to catch is done through the DropDownList Window. If you click somewhere onto your client area, the DropDownList Window receives the WM_KILLFOCUS event through it's WndProc(Message% m) method. Then sends to the parent window (the Base control) a WM_COMMAND (OCM_COMMAND) message with WParam=526318 (HIWORD(WParam)=8) and the Base control knows he should hide the DropDownList Window.
So, what you need to do is implement the additional DropDown Window and catch the WM_KILLFOCUS event.
The templates of the controls you've mentioned are using for the dropdown lists a popup as a container with the StaysOpen property set on false (which is the default i think).
ComboBox template example

Categories