942,520 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 547
  • VB.NET RSS
Aug 14th, 2010
0

passing process path to textbox

Expand Post »
I have a listview with process that are running. my goal is to pass the "path" of the process to a text box when someone clicks on a selection.

but my code isnt working correctly, this is what I have:

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub lvwProcBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvwProcBox.SelectedIndexChanged
  2. Dim pID As Integer = Int32.Parse(lvwProcBox.SelectedItems(0).SubItems(1).ToString)
  3. Dim proc As System.Diagnostics.Process = Process.GetProcessById(pID)
  4.  
  5. procPath.Clear()
  6. Try
  7. Dim selectCount As Integer
  8. For selectCount = 0 To lvwProcBox.Items.Count()
  9. If lvwProcBox.SelectedItems(selectCount).Selected = True Then
  10. procPath.Text = (proc.MainModule.FileName.ToString())
  11.  
  12. End If
  13.  
  14. Next
  15. Catch
  16. End Try
  17. End Sub

would be nice to fix i spent a week in google just trying ot find my solution.
and of course the text boxes path changes to a different path if a different selection is made
Last edited by p@rse; Aug 14th, 2010 at 8:01 pm.
Similar Threads
Reputation Points: 8
Solved Threads: 1
Light Poster
p@rse is offline Offline
30 posts
since Jun 2010
Aug 15th, 2010
0
Re: passing process path to textbox
vb Syntax (Toggle Plain Text)
  1. Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  2. TextBox1.Text = IO.Path.GetDirectoryName(CType(ListBox1.SelectedItem, Process).MainModule.FileName)
  3. End Sub
  4.  
  5. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  6. ListBox1.DisplayMember = "ProcessName"
  7. Dim p() As Process = Process.GetProcesses
  8. ListBox1.Items.AddRange(p)
  9. End Sub
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
691 posts
since Jun 2009
Aug 15th, 2010
0
Re: passing process path to textbox
After inserting the code I chnaged my keywords to match my value name. it asked me to chnage process(this has a blue squiggly line) to diagnostics.process so I did and then my lvwProcBox.selecteditem was not found so I changed it to: lvwProcBox.SelectedItems(Plural this time). Then I get the same squiggly blue line under the lvwProcBox and it says:

Value of type 'System.Windows.Forms.Listview.SelectedListViewItemCollection' cannot be converted to 'System.Diagnostics.Process'
Reputation Points: 8
Solved Threads: 1
Light Poster
p@rse is offline Offline
30 posts
since Jun 2010
Aug 16th, 2010
0
Re: passing process path to textbox
uhm the given example is only working for ListBox controls.

For ListView control this does the trick:
vb Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. Dim p() As Process = Process.GetProcesses
  3. For Each proc As Process In p
  4. Dim item As New ListViewItem With {.Text = proc.ProcessName, .Tag = proc}
  5. ListView1.Items.Add(item)
  6. Next
  7. End Sub
  8.  
  9. Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
  10. If ListView1.SelectedItems.Count = 0 Then Return
  11. TextBox1.Text = IO.Path.GetDirectoryName(CType(ListView1.SelectedItems(0).Tag, Process).MainModule.FileName)
  12. End Sub
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
691 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: MS Access Database linkage to VB.Net
Next Thread in VB.NET Forum Timeline: pls help me to change width of the messagebox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC