Good day, I am trying invoke a Listview and I can't get it to work.
I am getting the cross-thread error at line 31
Inspfolder is my variable for passing filepath from an excel worksheet.
I manage to get it working if I use:
Process.Start("explorer.exe", String.Format(Inspfolder))
But I'd rather have the whole folder content into my listview if someone can help me figuring how to pass it correcly?
I am getting the cross-thread error at line 31
Inspfolder is my variable for passing filepath from an excel worksheet.
I manage to get it working if I use:
Process.Start("explorer.exe", String.Format(Inspfolder))
But I'd rather have the whole folder content into my listview if someone can help me figuring how to pass it correcly?
VB.NET:
Imports System.Threading
Imports System.IO
Dim MonThread As New Thread(AddressOf Rangeloops) 'Thread for loops
Public Delegate Sub Callback(ByVal s As Control, ByVal v As Object)
Private Sub UpdateUI(ByVal this_Control As Control, ByVal vRange As Object)
this_Control.Text = CType(vRange, String)
End Sub
Private Sub ExecuteWork(ByVal value As String)
TextBox_selectednodes.Invoke(New Callback(AddressOf UpdateUI), TextBox_selectednodes, value) 'TreeView_Insp_Records.SelectedNode.Text = TextBox_selectednodes
Dim s As String = "Testing Worker Method"
Dim i As Long
Dim values As Object(,) = rg1.Value 'Range for fred
For i = 1 To values.GetUpperBound(0) 'rows
Dim Inspfolder As String
If values(i, 3) = value Then
TextBox1.Invoke(New Callback(AddressOf UpdateUI), TextBox1, values(i, 33))
Inspfolder = TextBox1.Text
ListBox1.Invoke(New Callback(AddressOf UpdateUI), ListBox1.Items.Add(Directory.GetFiles(Inspfolder)))
Exit Sub
End If
Next
Private Sub TreeView_Insp_Records_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView_Insp_Records.AfterSelect
Dim thread As New Thread(Sub() ExecuteWork(e.Node.Text))
thread.Start()
End Sub
Private Sub Rangeloops()
Dim i As Long
Dim values As Object(,) = rg1.Value
For i = 1 To values.GetUpperBound(0) 'rows
Dim Inspfolder As String
If values(i, 3) = TreeView_Insp_Records.SelectedNode.Text Then
TextBox1.Text = values(i, 33)
Inspfolder = TextBox1.Text
ListBox1.Items.AddRange(Directory.GetFiles(Inspfolder))
Exit Sub
End If
Next
Last edited: