TabControl TabIndexChanged won't fire - winforms

The TabIndexChanged event of the Windows Forms TabControl doesn't fire when I change between tabs. But the SelectedIndexChanged event is fired.
What is the explanation for this?

The TabIndexChanged event fires when you change the TabIndex property of the control-- the order of controls related to the parent form, etc. It has nothing to do with when the user is switching tabs.
Besides the SelectedIndexChanged event, you probably want to explore the Selected, Selecting, Deselected, and Deselecting events to determine what to do when the user is changing tabs.

Related

WPF Telerik gridview click events

I have a telerik gridview that I need to add both a single click and double click event. Basically the user can click a row once for a distinct event and then can also double click for a different event.
Initially I was using the SelectionChanged event to differentiate the two... but now I am having issues with anytime anything changes on the page, this event is fired.
If I implement a single click (MouseDown) event and a MouseDoubleClick event. The single click always overrides the double click and it cannot distinguish between the two - thus never making it to the double click event.
If you're using MVVM, you would probably prefer to attach an ICommand, which will be passed the DataContext of the row that has been clicked on, as a parameter.

Strange issue - mouse click in popup is getting captured by control underneath

I'm displaying a Popup in response to a button click (popup.IsOpen = true;). The popup contains a ComboBox, and when I click an item in the combobox, one of the things the SelectionChanged event does is to hide the popup.
The Popup appears over a DataGrid that I also have on my page, and I'm finding that the mouse-click on the combobox is also being picked up by a MouseUp event that I've got on the DataGrid. Any idea what's going on?
The MouseUp Event has a routing strategy of type Bubbling. Events that use this type of strategy get passed up the chain to parent controls. Since the Popup is a child of the DataGrid, the event will "bubble" up to the DataGrid. If you would rather the event not bubble, you can try using PreviewMouseUp, which has a Tunneling routing strategy, and will "tunnel" down the chain to child controls. Here is a decent overview of Routing Strategies.
I've hit the same issue. Oddly, it doesn't happen when the code is run in the debugger - it only happens in the release version. It really seems to be a bug in WPF. Trying to catch the click and set the event to handled doesn't work.
My workaround is to, when the popup opens, to tell the control underneath to ignore the click.

How can I prevent events being fired on the Winform when I click on a WPF popup?

I have a wondows form which contains a WPF control as well. When I click on the control it brings up a WPF popup control with a listbox. The goal is, when I select an item on the listbox, the windows form will be repopulated accordingly and the popup should get closed. The current implementation with SelectionChanged on the listbox works fine.
Here is the problem. The popup is big and covers some portion of the winform which contains some links. Now, when I select an item on the listbox, the popup closes after doing necessary actions, but if there is a link just below the popup (on the winform) that is under the cursor (when you selected the item on the listbox), that link is also taking the click event.
Is there any way to prevent the links getting clicked when I click on the popup? I have to close the popup though.
I think I figured this out.
SelectionChanged gets executed when we press the mouse key down and before we lift it.(Mouse key up). The popup gets closed in SelectionChanged before we lift the Mouse key. So, when we leave the mouse key, the keyUp event actually gets fired for a link on the Winform as the popup has been closed by now.
I moved the logic from SelectionChanged to PreviewMouseUp and the popup stays till I leave the mouse key and therefore the links on the Winform do not get the event. Of course, I check whether the selection has been changed or not.

How to detect a click on the selected row of a RadGridView control

My WPF application uses the Telerik RadGridView control on a few of its screens. I have a requirement that says that whenever the user clicks on a row in the RadGridView, I'm supposed to switch to another screen and display detail information about that row. I hooked up a handler to the SelectionChanged event and this works, except that nothing happens if the user clicks on the selected row a second time. This makes sense, as the selected row isn't being changed.
How can I detect a second click on the same row and have the second screen displayed?
Tony
You could just attach a handler to the MouseUp event on the GridView. Check if there are any selected cells and respond from there. This will fire even if there is already a selection.
The MouseDown event will fire on the mouse click, but before the gridview updates the selction, mouse up should fire when the selection has already been adjusted
You can also attach a handler to each individual cell in code-behind as follows
(this.GridView as RadGridView).AddHandler(
GridViewCell.MouseUpEvent,
new EventHandler<Telerik.Windows.RadRoutedEventArgs>(this.OnMouseUp));
I think you may try to achieve this through the MouseLeftButtonDown event or PreviewMouseLeftButtonDown event.

WPF composite Application - tab region - view not getting focus

I'm just starting to use the composite application libraries for WPF. In my shell I have a region in a tabcontrol that is used to display different types of views. I also have a toolbar with buttons hooked up to commands, for example save. The commands are bound in my views, and the views have the canExecute and execute methods.
The idea is that when i click a tab, my tool bar buttons should be enabled or disabled according to the methods in the view. Problem is when I switch tabs the view is not getting the focus and the canExecute for that view doesn't get called. The toolbar buttons remain connected to the commands in the previously selected view, and reminds that way until i actually click on the new view
I'm stumped right now on how to force the view to get the focus. I've tried looking at the tab's content when the tabs SelectionChanged and setting the focus there but its not making a difference. Any ideas?
Try listening for the View.Loaded event, then call View.focus() in the handler. Wpf will not accept focus requests before an element is initialized and loaded. Since the SelectionChanged event is raised before the view is loaded, the focus request will just be ignored. The loaded event is called each time the element is shown after being hidden.
See this blog post for more information on focus:
http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx

Resources