MultiSelectListBox (based on iLogic's InputListBox)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi folks. This is not really a question, just an offering, of sorts. I've known about this ability for some time now, but figured it was time to post it publicly here on the Inventor iLogic, API & VBA Forum, since we can no longer post them to our own knowledge base articles, and I do not want to operate my own Blog about this stuff. Just as the title indicates, there is a way to 'sort of' change the functionality of an InputListBox, so that you can select multiple items at once. No more having to use a regular InputListBox within a loop, and only being able to select a single item each time until you escape the loop.
How I discovered this:
When you type in "InputListBox" into an iLogic rule, you see that it originates from something called "RunDialogs". If you type "RunDialogs" directly into an iLogic rule, you see that it represents a Module (Link, Link) within "Autodesk.iLogic.RunTime". When you type "Autodesk.iLogic.RunTime" directly into an iLogic rule, you can see that it represents a Namespace (Link, Link). With that in mind, I started from that directly typed in "Autodesk.iLogic.RunTime" (unquoted), I could see many other things under it. By the way, you may also notice "GenericRadioButtonBox" listed in there too, which as you might have guessed, is the similar way to get more control over an iLogic InputRadioBox. Those are usually created from the ""Autodesk.iLogic.RunTime.RunDialogs" Module, but you can initiate your own, using the similar path mentioned above. The obvious advantage here is that you can access the actual System.Windows.Forms.Form Type object that these utilize, and therefore you can further manipulate them, as you wish. Of course you could just create your own Windows Form directly within the iLogic rule, but that may require a lot more code (and knowledge about that extra code).
Anyways, here is an example of the code used to create a custom Function I have used directly within iLogic rules, that presents an InputListBox, but allows you to select multiple items. You will notice however, the 'Return' Type being an IEnumerable(Of Object), since the InputListBox returned a single Object. I also did not include the last two options Height & Width, because I have never used them, and have never seen anyone else use them, but feel free to copy this and create your own variations that to include them. Or maybe don't even use it as a custom Function, and just use the Function's interior code directly if you want, but the input parameters are in a different order, not that it matters.
Sub Main
Dim oList As New List(Of String) From {"Option 1", "Option 2", "Option 3" }
Dim Selected As IEnumerable(Of Object) = MultiSelectListBox("Select Some", oList, Nothing, "Multi-Select InputListBox", "My List")
If Selected.Count = 0 Then
MessageBox.Show("Nothing was selected from the list.", "None Selected",MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
For Each Item In Selected
MessageBox.Show("You selected: " & Item.ToString, "Selected", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Next
End If
End Sub
Function MultiSelectListBox(Optional Instructions As String = vbNullString, Optional Items As IEnumerable = Nothing,
Optional DefaultValue As Object = Nothing, Optional Title As String = vbNullString, Optional ListName As String = vbNullString) As IEnumerable(Of Object)
Using oILBD As New Autodesk.iLogic.Runtime.InputListBoxDialog(Title, ListName, Instructions, Items, DefaultValue)
Dim oLB As System.Windows.Forms.ListBox = oILBD.Controls.Item(0).Controls.Item(2)
oLB.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple
Dim oDlgResult As System.Windows.Forms.DialogResult = oILBD.ShowDialog()
Dim oSelected As IEnumerable(Of Object) = oLB.SelectedItems.Cast(Of Object)
Return oSelected
End Using
End Function
This is why you could never find an InputListBox or InputRadioBox anywhere else within the general vb.net stuff...because they are unique to the iLogic ApplicationAddIn, and its associated resources.
If you like this content, or if this helped you out in some way, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)