- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I feel the answer is right in front of me but I can't seem to find why this doesn't work. I want to populate a combobox on each form load and the value to be the same as selected on the previous load.
The combobox is populated using this sub:
'Populate combobox Type based on part or assembly
Private Sub Set_Combobox_Type()
'Get the active instance of Autodesk Inventor
Dim inventorApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Dim Doc As Document = inventorApp.ActiveDocument
If TypeOf Doc Is PartDocument Then
' Populate cboType for Part documents
cboType.Items.Clear()
cboType.Items.AddRange(New String() {"A", "B", "C"})
ElseIf TypeOf Doc Is AssemblyDocument Then
' Populate cboType for Assembly documents
cboType.Items.Clear()
cboType.Items.AddRange(New String() {"D", "E"})
End If
End Sub
I made a variable to store the selected type, call the sub in the form load and try to store the selected value on form close so I can use it to put the combobox to the right value on the next form load.
'Variable to store the selected value of combobox 'Type'
Private SelectedType As String
Private Sub ModelMenu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Populate combobox for type
Set_Combobox_Type()
'Check if there is a previously selected type and set it
If Not String.IsNullOrEmpty(SelectedType) AndAlso cboType.Items.Contains(SelectedType) Then
cboType.SelectedItem = SelectedType
End If
End Sub
Private Sub ModelMenu_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
'Save the selected value when the form is closed
If Not IsNothing(cboType.SelectedItem) Then
SelectedType = cboType.SelectedItem.ToString()
End If
End Sub
But the value of 'SelectedType' is empty on form load. Is it not possible to use a variable on form load? It's stores values just fine if you call it with a button for example.
Anyone can point me in the right direction?
Thanks in advance!
Greets,
Frank
Solved! Go to Solution.