- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
I'm trying to code up my first Multiselect ListBox, but am getting a little lost in the methods available for execution. Here's where I've started - the below simply pushes ViewReps into an array and displays them as an InputListBox
Dim oAsmCompDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition Dim oViewRep As DesignViewRepresentation 'define view rep Dim viewRepList As New ArrayList 'define an arraylist to hold the list of view rep names For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations viewRepList.Add(oViewRep.Name) Logger.Info("For Each: " + oViewRep.Name) Next myValue = InputListBox("Select View Rep", viewRepList, State_List, Title := "View Reps", ListName := "Select View Rep") iProperties.Value("Custom", "Selected_ViewReps") = myValue iLogicVb.UpdateWhenDone = True
Unfortunately however it doesn't allow for user multi-selection (unless I'm mistaken?) - The user will be needing to process some ViewReps, but not all, so I figured that through a multiselect ListBox would be the easiest way for the user to progress with ViewRep selection, and their selections then execute via my main sub (not detailed here).
Researching the topic of Multiselect ListBox lead me to reading the below two articles;
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.listbox?view=windowsdesktop-6.0
So from these two articles, I can mash together a semi-functioning Multi-Select ListBox with string values, as per below;
However I've been unable to figure out how to inject my own viewRepList array list into my hacked up Autodesk / Microsoft article code example below;
AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Public Class WinForm
Inherits System.Windows.Forms.Form
'declare any thing here that you want to use/access throughout all Subs & Functions
Public oLargerFont As System.Drawing.Font = New Font("Arial",10)
Public Sub New() 'creates the new instance
oForm = Me
With oForm
.FormBorderStyle = FormBorderStyle.FixedToolWindow
.StartPosition = FormStartPosition.CenterScreen
.Width = 300
.Height = 300
.TopMost = True
.Font = oLargerFont
.Text = "Windows Form"
.Name = "Windows Form"
.ShowInTaskbar = False
End With
Dim oOptions As New List(Of String)
oOptions.AddRange({"Option 1","Option 2","Option 3"})
Dim oComboBox As New ListBox()
With oComboBox
'.DropDownStyle = ComboBoxStyle.DropDownList
.Items.Clear()
.Items.AddRange(oOptions.ToArray)
.SelectedIndex = 1
.SelectionMode = SelectionMode.MultiExtended
'.Top = oCheckBox.Bottom + 10
.Left = 25
.Width = 150
End With
'AddHandler oComboBox.SelectionChangeCommitted, AddressOf oComboBox_SelectionChangeCommitted
oForm.Controls.Add(oComboBox)
End Sub
Private Sub WinForm_FormClosing(ByVal oSender As Object, ByVal oFormCloseEvents As FormClosingEventArgs) Handles Me.FormClosing
If MsgBox("Are you sure you want to close this Form?",vbYesNo+vbQuestion, "CLOSE") = vbYes Then
Else
oFormCloseEvents.Cancel = True
End If
End Sub
Private Sub oComboBox_SelectionChangeCommitted(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
'oSender is a ComboBox
MsgBox("You just chose " & oSender.Text & " from the ComboBox.",vbOKOnly+vbInformation,"EVENT FEEDBACK")
End Sub
End Class
'This is the code that actually shows/runs the Form
Public Class RunMyForm
Private Sub Main
Dim oMyForm As New WinForm
oMyForm.Show
End Sub
End Class
I'm so very close to getting this working, but it's just a little bit deep-end of the pool for me, so to speak. Would appreciate any guidance, that's for sure! Or perhaps there's an easier way - such as, I have considered individual check-boxes as an alternative solution, but figured will try this MultiSelect ListBox method first.
Thanks!
Solved! Go to Solution.