Instantaneous event for DevExpress.XtraBars.BarEditItem check changed - vb.net

I am currently using DevExpress 11.2 within Visual Studio 2010. Currently I am using two DevExpress.XtraBars.BarEditItem which gives me two check boxes (with a label) in my menu bar (DevExpress.XtraBars.Bar) at the top of my windows form. Right now I have working code so that when one checkbox is clicked it unchecks/checks the other checkbox and executes code specific to that box. This works.
My problem is that the DevExpress.XtraBars.BarEditItem does not have a check changed event. Currently I am using the EditValueChanged event as the checked check box is set to True and the unchecked checkbox is set to false. However the EditValueChanged event isn't called until the checkbox looses focus. This doesn't work for me as I want it instantaneous. I looked into the itemClick and ItemPress events but they don't give me the new editvalue and if someone presses on the caption (rather than the box portion) it still fires. Is there someway to get the event right away??
I am looking in two different older projects (both in Visual Studio 2008 and using DevExpress 9.2 and 10.2) and it looks like it does everything the same way as me yet the EditValueChanged event fires right away without any lose of focus.

Actually what you want to do is use the events on the repositoryCheckEdit that is in the BarItem, rather than the barEditItems events directly. It will have CheckChanged and CheckStateChanged Events that you can use.
The repository Item that you want to use for the events will be listed in the Edit property of the BarEditItem.
In Code:
Dim item As New DevExpress.XtraBars.BarEditItem
Dim Editor As New DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
item.Edit = Editor
AddHandler Editor.CheckedChanged, AddressOf RepositoryItemCheckEdit1_CheckedChanged

Related

The ListBox Click event is lost when focus is set to a TabControl

I am working with a Visual Basic.NET project in Visual Studio 2017 (.NET Framework 4.6.1)
I am using a Listbox which is associated with a BindingSource.
The Listbox is contained within one pane of a SplitterControl.
I also have a TabControl is located within the other pane of the SplitterControl. This control contains child data associated with the items in the ListBox and is refreshed when the ListBox is clicked and an item is subsequently selected in the ListBox. The Click event refreshes a Treeview, which then populates the TabControl with data if/when (1) a tree node is clicked and (2) appropriate data is retrieved for that node.
The Listbox Click event works fine while clicking different items consecutively within the Listbox only.
However, once the mouse clicks in the TabControl (in the other pane of the SplitterControl), then once the initial Listbox is clicked, the Click event doesn’t fire.
I have researched this issue (on StackOverFlow as well as other forums) and suggestions have basically revolved around the idea that the Click event could be forced by calling the routine set up as the Click event handler (e.g., myListBox_Click).
I have tried this, but the problem is that I am losing the current SelectedIndex / SelectedValue.
To illustrate by reproducing the issue within the app where I am encountering the problem:
The app in question (note the Listbox highlighted by the red arrow - Screenshot 1):
Screenshot 1
Upon startup of the app, the Listbox behaves as it should, if the user clicks nowhere else, only selecting various items within the Listbox. The TabControl (initial tab shown is always the Profile tab) is refreshed accordingly.
However, if at any point, the mouse is clicked in the TabControl (e.g., to select another tab, note Screenshot 2)
Screenshot 2
Now, when the user clicks on another item in the Listbox, the wrong item is selected (shown in Screenshot 3):
Screenshot 3
The Click event is now being forced via a call to MyListBox_Click within the TabControl_Leave event; my thinking was that this was the appropriate place to put the subroutine call. My reasoning was that when the Listbox was clicked in this scenario, the first event to fire (as far as I could tell) was the TabControl_Leave event.
Not surprisingly, if the same item in the Listbox (in this example scenario, Allegheny) is subsequently clicked, than the result is what should have happened on the previous click (that the SelectedValue is correct, as seen in Screenshot 4):
Screenshot 4
Of course, this is correct, since the last click occurred while the Listbox was already the active control.
I have tried several approaches such as (1) using a global variable to store the current index/value and retrieving it, and (2) using the Tag property of the TabControl to store and retrieve the same value. This has either worked inconsistently or not at all because of the order in which the control events fire.
Hopefully, I've been clear enough on the nature of my problem/issue.
Anyone have any ideas on what my next approach could be? Any ideas/insights/suggestions will, of course, be greatly appreciated.
Thanks in advance,
Chris Fleetwood
Software Developer
North Carolina Partnership for Children (SmartStart)

How can a ContextMenuToolStripItem be displayed, without doing it programmatically?

I've taken over a project, which contains some UltraWinGrid controls on some of the forms.
On one of the original forms which has been there since before I took on the project, there is a ContextMenuStrip, which has just one ContextMenuToolstripItem on it, captioned 'Default for Column'.
This ContextMenuStrip is hidden by default, however, when the user right-clicks on the UltraGrid, the ContextMenuStripItem is displayed on the grid (rather than at the top of them form where the ContextMenuStrip is).
I'm trying to replicate this behaviour in a new form that I've added myself, however, after adding the ContextMenuToolstripItem in, I cannot get it to display when right-clicking my grid.
I've put a breakpoint on every subroutine in the in the older forms class, and none of them are triggered when right-clicking it.
Additionally I have also searched the class for DefaultForColumnToolstripMenuItem, and the only place it appears is in the Click event of the ContextMenuToolStripItem itself.
So, how else is it possible to show it when right-clicking the grid? I've copy and pasted the ContextMenuStrip from the old form onto the new form and still nothing occurred.
I'm assuming it's in a property somewhere that I'm missing?
Check for a ContextMenuStrip property on the UltraWinGrid. You can set it in the designer and your context menu will appear on right click without having to deal with the MouseClick handler, checking the mousebutton used, etc.

Checkbox with image and autosize

In Word 2012 I have seen the following checkbox:
I am wondering if this checkbox is a .NET control with an image assigned to it (with property "imagealign" being middle right) or if this is a custom solution by MS for their Office GUIs.
I can reproduce the appearance, but I am unable to easily check if the user clicks the checkbox (and wants to change its state) or the info button and wants to show the tooltip.
Also, I have to add some spaces at the end of the checkbox text, else the image is under the text if the checkbox autosize property is set to True.
I would tend to think that the checkbox is a custom solution by MS or perhaps the image is a separate control.
Does anybody know more about this?
I think you are looking for
Checkbox.AutoSize = False
CheckBox.Image = "Your Image"
CheckBox.ImageAlign = MiddleRight
But this way you won't be able to distinguish if the user clicks the checkbox or the info button to show the tooltip.
As far as I know, there is no control available at .NET which allows this behavior, so I suppose they are using separate controls.
I think you'll need to use a PictureBox near the CheckBox and then use CheckBox_CheckedChanged and PictureBox_Click events to do whatever you want on each case.

VB.NET: How to change setting on Click events

Visual Studio with VB.net: If I create a copy of a button on the forms designer, the click event is added to the click event handler of the source button.
How do I change this behaviour ? I want the click event of the second button be wired to a totally new click handler code, not to the already existing one of the first button.
There are two ways to copy a button.
CTRL+C / CTRL+V (or same with right click menu). This will create a new button with a new event handler. Note that this new event handler is not created automatically, but will be created on button click in VS designer.
CTRL + drag a control into a new location. This will create a copy with the same event handler, i.e. add an event handler to already existing one. This is the behavior you are seeing.
I'd be interested to know the official reference about this behavior, found the above by experiment. I've used CTRL + drag copy method 95% of the time, and had the same question for quite a while. Fortunately, there is a quick fix for event wiring - read below.
If you used the wrong method, you can manually delete the wiring code (the second handles clause), then double-click the button in question to create new click event handler for it (not a big deal).

TabControl.SelectedIndex being changed, but SelectedIndexChanged even not firing

All,
I have a TabControl in an application that started behaving strangely. Some background...
This program was converted from VB6 to VB .NET 2008, and used to refer to forms using their class names. In other words, I might have a form class called frmFoo. In the code for the program you might see:
frmFoo.Show()
or
frmFoo.UserDefinedProperty = True
During some recent changes, I created variables to represent instances of my forms much like these:
Public MyForm as frmFoo
MyForm = New frmFoo
MyForm.Show()
In doing so, I also removed code from the form's Load event handler and put it in the form's constructor.
When the form loads, or when a document is loaded and should influence the TabControl's selected index, something like the following will not necessarily fire the SelectedIndexChanged event.
MyForm.tbsForm.SelectedIndex = ValueReadFromFile
...or...
MyForm.tbsForm.Tabs(ValueReadFromFile).Select
Sorry to be so wordy, but there's more. If I open the form and look at the TabControl to verify that it's been set properly, everything works like it's supposed to. The misbehaving TabControl is contained within another TabControl, so I have to click the parent TabControl to see it. If I can see it, and run a test, the test always works. If I can't see it, and run a test, the first test I run will not fire the event. ...paging Dr. Heisenberg...
It's almost as if the control has to be initialized first by changing the value or making it visible onscreen...I'm totally lost on this one. It's the most unusual behavior I've ever seen. And everything worked perfectly before I began using variables to represent forms and placed the Load event code into the form constructors.
Can anyone help, or at least put me out of my misery?
SH
-------------------------------------------------------------- Edit #2
I just performed a test after having attempted to eliminate some of the variability in the behavior. But I wanted to confirm the previously-stated behavior.
I opened the program and read a file. This file contained a value that should have triggered the event handler. Without making the control visible, I can change the SelectedIndex property of the tab control without the event firing.
I closed the program down again, and reopened it. This time, selected the parent tab that allowed the child tab (the one whose event I'm concerned with) to become visible. I then selected a different tab in the parent control, meaning that the child control was no longer visible. When I opened the same file as before, it fired the event.
I'm tempted to implement a flag that confirms that the control has been repainted or whether the parent tab has been displayed. I may have to fire the event in code if the flag isn't set.
I want to reiterate that everything worked when the program referred to the forms by their class names and much of the arrangement of controls on the forms was done in the load event. Now the program creates variables and the arrangement of the controls is done in the form's constructor. I'm sure this has something to do with the problem I'm having, but I can't understand how. Any wisdom to share?
MyForm.tbsForm.SelectedIndexChanged = ValueReadFromFile
doesn't make a lot of sense. Is tha trying to assign a handler to the SelectedIndexChanged event? or is ValueReadFromFile the name of the tab?
What you're saying is that you have two tab controls, say, A and B. Tab control B is contained within a tab of A, and unless A has the tab page selected that contains the tab control B, the SelectedIndexChanged event of B will not fire if you change its tab programatically?
In which different ways have you tried to select a tab within the child tab control, and when is this code being executed?