Combobox selection enabling another combobox - wpf-controls

I was wondering if there is anyway to set a binding to enable a combobox if a parent combobox has any selection in it.
For instance, I have three comboboxes, Job, Type and Task. You should only be able to select them in that order.
I know I could do it easily with code behind but if there is a way to do binding I think I'd like to do that instead.

Related

VBA Dynamic Userform Population Based on which Module Called It

I have a user form where individuals can add details about tasks that populate a project planning table. If someone is creating a new task, all of the controls initialize with blank values. However, I want to create the ability for them to modify an existing task and along with it to populate the same user form's controls with the inputs that were originally submitted upon its initialization so they can tweak only what they need and not have to fill it out entirely.
I think there are several ways I could approach this, either by somehow passing variables from the EDIT TASK module to the userform or by potentially initializing the userform from the CREATE TASK and EDIT TASK modules themselves and populating the values of the controls from there like so
Sub Show_Insert_Task_Form()
INSERT_TASK_FORM.Show
INSERT_TASK_FORM.TASK_TBOX.value = "VALUE"
End Sub
This code runs, but it does not populate the textbox unfortunately.
What is the best way to approach this?
Your Show_Insert_Task_Form actually does populate the textbox.
From the behavior you are describing, I can deduce the ShowModal property (in the property window) of your form is True. When that is the case, VBA pauses the execution until you close the Window. In other words, what your code does is:
Show the form in modal mode.The textbox is not populated yet and as the form is modal, the execution is paused.
When you close the form, the execution resumes and the textbox gets populated (too late for you to see).
Solution:
You must populate your form before calling Show.
Sub Show_Insert_Task_Form()
INSERT_TASK_FORM.TASK_TBOX.value = "VALUE"
INSERT_TASK_FORM.Show
End Sub
Doing so means the code will pause after the form is populated.
About making the form non-modal:
The 2 changes below stop the execution from pausing:
Change the ShowModal property to False in the property window.
Call INSERT_TASK_FORM.Show False.
Both these alternatives are apparently a valid solution to your problem (without the execution pausing, the form gets populated while displayed on screen). However, they also make the bug prone to reappearing (example: if one day you change your mind and change the form back to being modal).
Good news is: the solution as well as these alternatives are not mutually exclusive. I recommend you implement the solution as well as alternative 1, alternative 2, or neither or both alternatives.

Combo Box not showing on Excel VBA Form

I have a form with multiple Combo boxes. I was doing some appearance tweaking of the form and one of the boxes is not showing anywhere. If I try to add a new combobox with the same name it says it is not unique.
I tried Opening the form with a message in the box "Here I am" but it did not show. I don't get any compile errors as there are multiple references to the field in my code. Is there anyway to find it (Me.cmb_Photographer)?
It could be a bunch of different things. Perhaps the visible property is set to No or the control is behind another control. You might also have mislabeled something so Name property is different from the Control Source property.
In any case you should be able to go into design mode, open the property sheet and use the dropdown to find the control you're looking for. It should highlight the control on the form.

VBA Listbox not updating to reflect new source list when called from itself

Edit:
Playing around further, it seems that you can't assign a new array to a listbox via the .list=somelist approach when the assignment happens in response to a click on the listbox itself. Or rather, you can assign the list, but it simply won't visually populate the listbox...although Excel seems to think it's there.
The .additem or .removeitem methods do however result in a visual change when called from a listbox click, which means you have to build your new array up that way I guess. How tedious.
You can however feed a listbox an entirely new array using the .list=somelist approach via a CommandButton-initiated action. But the user has to obviously click a button to do this. Which in my case below defeats the purpose.
Edit Over.
I'm designing a UserForm to help filter PivotTables. It's a cross between the existing Pivot Filter functionality and a Slicer. Here's what you see if you double-click on a PivotField header:
Note the Search field at the top, and the three buttons immediately below that search field. If you type something into that field, then instead of displaying everything that's currently filtered, you instead get a list of any matches, and you can then apply those search results to the underlying PivotTable via those three CommandButtons. The first cb simply filters the PivotTable to reflect the search, and the other two let you add or remove any search result from an existing filter.
I want to do away with those three command buttons, and instead (in the event that a search is performed) simply list those three options at the top of the ListBox above any search results returned. Clicking on those three options will then trigger the exact same code as currently triggered by the Command Button.
Here's how that looks currently if I actually type something in that Search box (Note I haven't yet removed the three command buttons this does away with from that Search frame):
I've added a simple bit of code to the lbResults_Change() event handler that checks if a user clicks any of those first three options. All that code does is trigger the exact same routines as would be triggered if they'd simply clicked on the actual command buttons themselves:
For i = 0 To 4
If Me.lbResults.Selected(i) Then Exit For
Next i
Select Case i
Case 0: cmdApplySearch_Click
Case 1: cmdAddToFilter_Click
Case 2: cmdSubtractFromFilter_Click
Case 3: Me.lbResults.Selected(3) = False
End Select
Here' the problem: The listbox gets updated just fine if I click on those command buttons, as you can see from the below. The Pivot has been filtered accordingly, and those contextual search options have been removed from the top of the listbox (and the search field cleared):
But the listbox does NOT get updated if the exact same routine is triggered from a click on one of those top three options in listbox itself:
As you can see from the above screenshot, it still shows those three options at the top, even though they are NOT in the array that I assigned to the listbox, as evidenced by the screenshot below:
But as you could see from the earlier screenshot, it shows 7 items in the ListBox instead of the three there actually are. But there are indeed just three items that should be showing in that list box:
? .ListCount
3
? .List(0)
263213: ICT Systems Test Engineer
? .List(1)
263299: ICT Support and Test Engineers nec
? .List(2)
839313: Product Tester
Basically, as soon as I try to update what's in the listbox via a click on the listbox itself, I can't update it.
It doesn't seem to matter if I set focus to something other than the listbox before the filtering code executes, and I've even tried completely clearing the Listbox with .clear. It just doesn't clear, until I manually click on one of those command buttons again.
Anyone have any pointers?
Ah, what an idiot I am for overlooking the painfully obvious solution. The ListBox list happily redraws in response to any event other than the ListBox_Click event, right? So all I needed to do was to use the ListBox_Click event to determine what got clicked (as I currently do), and then use the ListBox_MouseUp event to trigger the actual updating of the ListBox list. Works a treat.
Hopefully this post will save someone else two days of pain in the future. Probably me.

How do I enable a range selector on an Excel ribbon bar?

What is the standard practice for adding range selection controls to a ribbon bar in Excel? I'm creating an Add-In and need to enable the user to define a series of ranges. Here's a link to a question with an illustration of what I want Provide a range selection tool/utility to the user in Excel VBA. The answer to the question however only works in the context of a winform. My research suggests you can't use RefEdit controls directly in a ribbon bar. Is that true? If so, what solution do you recommend? I considered creating a button that triggers a popup containing a RefEdit control, but that strikes me as a poor user experience since it involves additional clicks by the user.
Unfortunately, you are correct: the RefEdit control cannot be used within a ribbon. However, you can use a button control to populate an editBox control with the currently selected range, using the editBox's getText dynamic attribute. This will not only place a control within the ribbon that displays the selected range and holds the value there with a single click, but -- if needed -- other automated processes can be executed as well.

How to select the first item of a combo box in an Access Web-compatible form?

I've created an Access Web database on SharePoint 2010 and I'm editing its forms with Access 2010.
One form includes a set of cascading combo boxes that I've created following these tutorials
Combo Box in Access and Cascading Combo Boxes. The actual data binding is working as expected.
The issue is that when the cascaded combo boxes receive their bound values, the selected item is left blank and I'd like it to pick the first element by default i.e. combo.items(0)
I understand that I'll have to add some sort of macro to select the first element. However, I haven't found a way to do so.
Currently the primary combo boxes invoke through an after update event a requery action on the cascaded combos.
Is there another action that could force as well the selection of the first bound item?
Take a look at http://www.access-programmers.co.uk/forums/showthread.php?t=38754
You can do this trick OnLoad. So your VBA code behind the form will look something like:
Private Sub Form_Load()
Me.cboTestCombo = Me.cboTestCombo.Column(0, 0)
End Sub
You may need to play around with the indices on Column(N, N) - the example above worked for me to place the first entry from my data rowsource in the combo at start.

Resources