When I click the first item in a multi-select listbox the first click triggers the clicked item as well as items around it.
Many selected
I dug into why and added code to listen to the listbox selection changed event, adding only the selection changed listener and no code made it go away.
Private Sub AllListBox_SelectedIndexChanged
It comes back every so often. Maybe it has to do with the multiselect.
The values are added programmatically by looping through every header on the page and adding it as the value.
Dim InList As Boolean
For Each col In Range(DataRangeBox.Value).Cells
'Find the row with the headers on it
If col.row = Range(DataRangeBox.Value).Cells(1).row Then
'Add item to all available list box
If IsNull(AllListBox) Then
AllListBox.AddItem col.Text
End If
End If
Next col
Is it similar to the problem discussed here. Will adding the index explicitly solve the problem?
One selected now
Solved my problem.
On the listbox properties there is the attribute "Multiselect" and I noticed that it was on "fmMultiSelectSingle" when I was getting the problem. I knew I put it on "MultiSelectExtended" as its setting when I created it. So I played with it and once I had it on the one I wanted, I didn't see the problem. I could also reliably reproduce it by making it "fmMultiSelectSingle".
I'm having the same problem described: Usually, the first time (only) clicking an item in a listbox, I see 4 items selected (one clicked and 3 below it). For me, the listbox's Multiselect property is properly set to MultiSelectExtended so not what was described above. I've confirmed no code is setting the listbox property otherwise and I've tried manually changing the property to Single and then back to Extended but the problem persists.
I have my problematic listbox on a tab. After opening form/screen, user works in one tab before clicking on this other tab. (When going to this tab with listbox, some brief code runs.)
MY SOLUTION:
Today, I decided to add code to use SetFocus for the listbox after user clicks on that tab (at the end of the brief code that currently runs). So focus is on the listobx before I click any item in the list for the first time. This fixed my multiselect issue! Now, only the item clicked in list is selected, correctly.
I hope this idea helps someone else experiencing this quirky problem.
Related
is it possible to write the value of a combobox to a cell but only when a user selects an item from the combobox but not if the userform refreshes and clears the combobox?
Szenario: I have a userform with 3 comboboxes. In these 3 comboboxes, the user chooses 3 items. Below these comboboxes, there is another combobox where the user can yet again chose an item, however, the given items are the previously selected items.
I solved the situation by using combobox.click and save it to the spreadsheet everytime it gets selected. However, if I now refresh the userform the cells get changed to empty and the cells get cleared out (as combobox.click gets triggered by that as well).
Anyone got an Idea?
Although this is mainly a theoretical question, I will be happy to provide any specific code. As my current code is over 2000 lines, it would be a bit much for SO.
I'm doing an userform where in one of the fields (lets say its combobox1) the user is asked for the number of failures, and for each failure he has to put the type of failure, number of part and in another field the type of rework (3 fields to fill for each failure). And what I would like to know if that if it's possible to generate comboboxes depending on the number of failures made. For example: if the user puts 3 in the field of failures, 9 comboboxes should appear and so on.
I also think that maybe another way would be to have the standards 3 comboboxes and clear the fields each time the user press a button and a counter appears indicating which failure description he is filling, but I would also like to know how this could integrate into the whole userform, which already has a "submit" button.
Maybe there could be another reasoning for this, and I would greatly appreciate any help.
I don't really have much experience using dynamically created tabstrips, but they may be helpful with creating the layout you're describing. I would recommended in the base userform, include a tabstrip with a single tab and the 3 comboboxes/textboxes that are needed for a single failure. (You could keep it invisible until after "combobox1" has a value, if desired) Then use the number from the combobox to dynamically create the additional tabs on the tabstrip:
Private Sub ComboBox_Change()
'To remove previous tabs if combobox changed
For i = 1 To TabStrip1.Tabs.Count - 1
TabStrip1.Tabs.Remove(i)
Next i
'Adding additional tabs to tabstrip
For i = 1 To ComboBox.Value - 1
TabStrip1.Tabs.Add
Next i
End Sub
The tab currently selected can be identified by using the TabStrip1.Value property. I think the change event is queued by the TabStrip1.Value changing.
You will have to manually clear out any values when the tab strip changes (or fill back in values they previously filled out but want to view again).
However, since you'd be determining which tab you're on by "index" (the .value property) you could create a 2d array (redim it to correct rows/columns based off combobox1's value) and use the tab "index" to store combobox values and retrieve existing values for when the user switches back to an existing tab.
And maybe consider "locking" the combobox1 so the value can't be changed by accident. This could be accomplished by having a variable initialized to, maybe -1, which gets set to the combobox value after they've started adding infor to the incidents. Or don't remove any tabstrip tabs, only add if the number is greater than the existing count. (If you want them to put in whatever value they'd like, maybe consider using a textbox?)
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.
I've got a custom control based on a Datagrid. What I want to achieve is doing multiple selection of rows and then right click on the row selector to open a context menu.
What actually happens: Selection of multiple rows works fine until the user right clicks on the row selector. Once that is done, there is only one selected row the one over which the right mouse button was clicked.
What I need to happen: Allow the user to do a multiple selection (rows have a style for selection) and right click to open the context menu without loosing the previous selection.
What do I need to do?
No it doesn't happen like that at all. Make sure that you have DataGridView MultiSelect property set to TRUE. Then assign your ContextMenustrip control to the datagrid's ContextMenuStrip property.
That should do the work and multiple selection should remain on right mouse click as well unless in your code behind somewhere you are altering that.
In which case, you will have to debug and find out where and how.
Just revisited the code and found that I was not updating the SelectedItems IList:
Dispatcher.BeginInvoke(new Action(delegate
{
foreach (var item in e.RemovedItems)
{
SelectedItems.Add(item);
}
SelectedItemsList.Add(SelectedItem);
}), System.Windows.Threading.DispatcherPriority.ContextIdle, null);
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.