I have a combobox with values that when selected, lead to other questions.
I have a button that I want to be an "Up one level" button that clears all the following questions. It should reset the display of of the combobox to nothing, like before any options were selected, so the user can make a selection.
I tried setting the Value = 0, the ListIndex = -1.
I don't want to use "Clear" because I want to preserve the values in the combobox.
I looked through the properties of a combobox and I can't pick out which one will do what I want.
Listbox.Value=null
should do the trick.
If you use: ComboBox1.ListIndex = -1 with no list items then there will be no effect. This is a problem if you're dynamically loading the items. Use: ComboBox1.Value = Null to clear the value as mentioned above.
I faced the same problem and possibly we have the same scenario.
I understand that you don’t want to run clear method and make the current listed items vanish, but just make the combo having no value.
In case just before the attempt of making combo value null or blank string ("") or ListIndex=-1 you had repopulated the combo with new set of items this might happen. Before repopulating the combo with new items, you should call the clear method and then repopulate the combo with the new items and after that set the value to null or blank string ("") value.
Related
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?)
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.
[22 Feb 2016 update]
Regarding my previous questions about list box, I can move values between two listboxes and save values after I receive useful answers.
However, if I retrieve those saved values, the listboxes can display the proper values but I cannot move those values and get exception message.
I can only move values between two listboxes if I don't save them.
Therefore, I am planning to have another button for delete listboxes values. I am not sure this is a good practice/design in xpages but I don't have a better method solve the exception.
I am sorry if I caused any inconvenience in this question. Thank you.
[23 Feb 2016 update]
According to the latest comments and answer, I notice that I made a big mistake because I mixed the document and value together.
I decide to break the design into few steps to find the problem occurs.
Due to I can move values between two listboxes and save them. I use another listbox test whether I can retrieve those saved values or not.
The third list box, I use View Scope Variable(similar to listbox B) but I use another variable name to avoid vague.
Here is my code of the third listbox:
var item = getComponent("comboBox4").getValue();
if ((item == null) || (null == item))
{
return "void";
}
else if ((item != null) || (null != item))
{
var lookupItem = #DbLookup(#DbName(),"ViewName", item,3 )
return lookupItem;
}
if (!viewScope.totalItems)
{
viewScope.totalItems = [lookupItem];
}
return viewScope.totalItems;
In the combo box, I use onchange partial update and apply to the third list box . When I run the program, I select a value from the combo box, the third listbox can display the relevant values that I saved before.
That part is fine, so I keep the third listbox for testing. And I put some dummy but unique data (to prevent confusion) related to the combo box.
Here is my first attempt: I choose a value from a combo box, the third listbox can display the relevant values that I saved. I move one value from listbox A to listbox B and click save. The third list box can reflect the value that I save.
In my second attempt: after the first attempt, listbox B still contains the value from listbox A, so this time, I move that value back to listbox A and click save. In the result, in the third list box, I see that value disappear.
At this moment, there is no value in listbox B and I add another two button and write similar code to pretend move values between the third list box and listbox B.
I test it, I select the value from the combo box, the third list box shows the proper values. But when I select a value from the third list box and click the button to move it to listbox A. I think that value will move to the listbox A but the result is nothing happens.
I try the other way, I select a value from listbox A and click the button to move it to the third button. Again the result is nothing happens.
After those fail attempts, I think the problem occurs in the buttons.
Here are the code of the two buttons
Button 1 (move value to the third listbox):
if (viewScope.ALstBoxItem) {
var sel = [].concat(viewScope.ALstBoxItem);
for (var i = 0; i < sel.length; i++) {
viewScope.totalItems.add(sel[i]);
viewScope.AselectItems.remove(sel[i]);
}
viewScope.totalItems.sort();
viewScope.ALstBoxItem = "";
}
Button 2 (move value to the listbox A):
if (viewScope.TotalItemsVariable) {
var sel = [].concat(viewScope.TotalItemsVariable);
for (var i = 0; i < sel.length; i++) {
viewScope.AselectItems.add(sel[i]);
viewScope.totalInItem.remove(sel[i]);
}
viewScope.AselectItems.sort();
viewScope.TotalItemsVariable = "";
}
Recall to comments in the question, I guess I should focus on the values in the listbox, not the button. I search on the internet about hide selected value and find these websites almost can give me the idea to solve the problem:
xpages hiding/showing fields based on a combobox value
Hiding based on previous combo box choice in xpages?
https://www-10.lotus.com/ldd/ddwiki.nsf/dx/dynamical_elements_on_xpages.htm
I try to apply those summary to suit my case but I still cannot move values after I save.
Grateful if someone can give advice please. Thank you very much.
Please step back and think about what you are building. You have two list boxes. They contain values, not documents, so a deleteSelectedDocument simple action can't work. Similarly, access to delete documents isn't relevant.
Also, from previous questions of this topic, I don't think you are setting values in the listboxes, you are using the events to set options, i.e. the options are not highlighted and so selected in the listbox, they are just sitting in the listboxes as options available for selection. Look at the code you're using to add options to the listboxes and use the corresponding code to remove the options.
I've added an image that corresponds to what I think you're trying to build, and the difference between "value" and "option", except in your example it sounds like you're moving the option from ListBox 1 to ListBox 2 as soon as it's selected, not using an "Add" button. Or to break the process down further, it sounds like, when an option in ListBox 1 is selected, you are looking to remove it from the list of options in ListBox 1 and add it to the list of options in ListBox 2. On your save, it sounds like you're wanting to store the options into a NotesDocument and, when you return, set the options for your ListBoxes based on what is stored in the NotesDocument.
If so, the questions and answers on this topic have given you everything you need to code those steps in the process.
I was wondering if this is possible to do or not. I am pretty sure it’s not, but wanted to see if it was and someone else might know how. I am using Excel 2010 and everything is being done with VBA. What I would like to do is set a ComboBox with a minimum width size and then AutoSize if typed data becomes longer than the length of the ComboBox.
OK, so let me clarify some misconceptions or questions that I am going to get asked about, such as why I would want to allow users to type in a ComboBox. On another sheet, apart from the sheet that the ComboBox is on, I have a list of items. As items are typed in here the ComboBox is populated with the new item, I also have it sorting the list in alphabetical order and it spell checks them too, as they are being added.
I then have the code to also check for the longest length of text in each cell and the ComboBox will size to the longest length of text within its list, so it can fully be read in the dropdown.
I also want users to be able to type in the ComboBox for items that are not in the list already. The list is for just the most common items used, but often other miscellaneous stuff needs to be entered. I don’t want the miscellaneous stuff added to the list within the ComboBox, so I just want the user to be able to type in data within the ComboBox, but if it is used a lot they can add it to the list on the other sheet.
In case someone is wondering, I do have spellcheck working for the ComboBox when users type data in. All I did was make the cell that the ComboBox is over equal to the text in the ComboBox when the ComboBox is deactivated (LostFocus), then I spellcheck that cell, followed by making the ComboBox equal to the cell that was just spellchecked.
Anyway, as already mentioned I do have the ComboBox’s width set to the longest item in the list using code. Is there a way that I can somehow keep the ComboBox’s minimum width set to this size, but then the width will increase when the user is typing data in that becomes longer than what the box is currently set to? I am guessing this would be easy to do if I was to adjust it after the user finished typing (when the ComboBox LostFocus), but is it possible to do this while they are typing? Setting the AutoSize will not work, because it will ignore the size of the longest item in the list, and shrink to almost nothing, making it impossible to see the items in the list. The other issue with AutoSize is that you can’t read items in the list as you are typing. Like when you are typing it will prefill items from the list as you are typing, but the prefilled items can’t be read when using AutoSize.
I guess it is possible to do, I just figured it out. The iLength is what determines the default minimum width size should be, which is slightly larger than the size of a column in a different sheet where the ComboBox is pulling its data from. I just did some basic calculations to figure that the length (character count) of text being typed in the notes field is about 4.5 times smaller than the default length. Of course, the 4.5 would change if I used a different sized font. If the typed text (based on the calculation) becomes greater than the default size, I set the ComboBox to AutoSize, otherwise AutoSize was set to False. Then when I cleared the data from the field I just have the code in the clear button to reset the ComboBox back to the default size and to set AutoSize to False. This works perfectly.
Private Sub cboNotes_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim iLength As Integer
iLength = Sheets("Notes").Range("A1").Columns.Width + 20
If Len(cboNotes.Value) * 4.5 < iLength Then
cboNotes.Width = Sheets("Notes").Range("A1").Columns.Width + 20
cboNotes.AutoSize = False
Exit Sub
Else
cboNotes.AutoSize = True
Exit Sub
End If
End Sub
I have a sharepoint list with several columns, one of which is a text box that is set to accept numbers. I would like to auto populate a drop down box based on the number entered into that text box.
I am not very code-savvy, and so far all the answers I have found involve getting a number/value from a drop down box to insert into a text field, not the other way around. Any help would be greatly appreciated!!
You need to set the SelectedValue of the dropdown in code based on the textbox value. You need to add an event handler to the textbox (I believe KeyPressed event should be a good start)