Results 1 to 16 of 16

Thread: [RESOLVED] Passing checked items/process to other form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Resolved [RESOLVED] Passing checked items/process to other form

    Hi,

    Anyone can help, pass all checked listview items into my install form??

    And then start process in install form... Here's what I have:
    Code:
    If ListView1.CheckedItems.Count > 0 Then
                For Each Item As ListViewItem In ListView1.CheckedItems
                    '//Install
                    'install = lVI.Checked
                Next
                Me.Hide()
                InstallPrograms.Show()
            Else
                MessageBox.Show("Nothing selected to install!")
    
            End If

  2. #2
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Question Re: Passing checked items/process to other form

    Just a suggestion, there could be other ways. But I had a similar problem last time and was recommended something like this.

    Create a module with a class of booleans for each install checkbox.
    If the checkbox is checked change that boolean to True.

    vb.net Code:
    1. Module Module2
    2.  
    3.     Public setting As New installsettings
    4.  
    5.     Public Class installsettings
    6.  
    7.         Public Property var1 As Boolean
    8.         Public Property var2 As Boolean
    9.         Public Property var3 As Boolean
    10.         Public Property var4 As Boolean
    11.  
    12.     End Class
    13. End Module

    Then for each check box do something like this

    vb.net Code:
    1. Private Sub chkvar1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chkvar1.CheckedChanged
    2.         if chkvar1.Checked = True then
    3.             setting.var1 = True
    4.         else
    5.            settings.var1 = False
    6.         End if
    7.     End Sub

    Then in your install Form you can access them like this

    vb.net Code:
    1. if settings.var1 = true then
    2.    'Install var1....
    3. End if

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    So you're saying to replace all this:
    Code:
    Public Class InstallPrograms
        Dim pCount As Integer
        Dim p() As Process
        Dim inifile As String = Application.StartupPath + "/Start/InstallCFG.ini"
        Dim stream_reader As New IO.StreamReader(iniFile)
        Dim line As String
        Dim ReadResult() As String
    
        Sub Form1_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyUp
            If e.KeyData = Keys.F1 Then
                Editor.ShowDialog()
            End If
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            line = stream_reader.ReadLine() 'Read InstallCFG.ini File
    
            Do While Not (line Is Nothing)
                ReadResult = line.Split(":") 'Split line at :
    
                If (ReadResult(0).ToLower() = "prog name") Then
                    Label3.Text = "Installing " + ReadResult(1)
                End If
    
                If (ReadResult(0).ToLower() = "installer file") Then
                    PictureBox1.ImageLocation = ".\images\System-Working.gif"
                    Label3.Refresh()
                    Label5.Refresh()
                    Dim info As New System.Diagnostics.ProcessStartInfo
                    info.FileName = ReadResult(1) 'Open the application
    
                    Dim myProcess As New System.Diagnostics.Process
                    myProcess.StartInfo = info
                    myProcess.Start() 'Start the process
                    myProcess.WaitForExit() 'Wait until the process started is finished
                    myProcess.Close() 'Release the resources
                    Label5.Text = "Install Complete..."
                    Label5.Refresh()
                    System.Threading.Thread.Sleep(750)
                    Label5.Text = ""
                    Label5.Refresh()
    
    
                Else
                    MessageBox.Show("Something is wrong! File = " & ReadResult(1))
                End If
    
                line = stream_reader.ReadLine() 'Move on to the next line.
            Loop
            stream_reader.Close()
    
            ' We'll assume you have all the filepaths in a listbox
            ' it would work the same for any other collection type
    
            pCount = ListBox1.Items.Count
            ReDim p(pCount - 1)
    
            For i = 0 To pCount - 1
                p(i) = New Process With {.EnableRaisingEvents = True}
                AddHandler p(i).Exited, AddressOf ProcessExit
                p(i).StartInfo.FileName = ListBox1.Items(i).ToString
                p(i).Start()
            Next
    
        End Sub
    
        Private Sub ProcessExit(ByVal sender As Object, ByVal e As System.EventArgs)
    
            pCount -= 1
            If pCount = 0 Then
                MsgBox("All Done")
            End If
    
        End Sub
    End Class-
    with ur code......

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    Sorry, got ya... That's not good m8, as i'm reading from a .ini file, can be any amount of installs 10+/20+/30+/40+/80+/100+

  5. #5
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: Passing checked items/process to other form

    Quote Originally Posted by chris-2k View Post
    So you're saying to replace all this:
    Code:
    Public Class InstallPrograms
        Dim pCount As Integer
        Dim p() As Process
        Dim inifile As String = Application.StartupPath + "/Start/InstallCFG.ini"
        Dim stream_reader As New IO.StreamReader(iniFile)
        Dim line As String
        Dim ReadResult() As String
    
        Sub Form1_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyUp
            If e.KeyData = Keys.F1 Then
                Editor.ShowDialog()
            End If
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            line = stream_reader.ReadLine() 'Read InstallCFG.ini File
    
            Do While Not (line Is Nothing)
                ReadResult = line.Split(":") 'Split line at :
    
                If (ReadResult(0).ToLower() = "prog name") Then
                    Label3.Text = "Installing " + ReadResult(1)
                End If
    
                If (ReadResult(0).ToLower() = "installer file") Then
                    PictureBox1.ImageLocation = ".\images\System-Working.gif"
                    Label3.Refresh()
                    Label5.Refresh()
                    Dim info As New System.Diagnostics.ProcessStartInfo
                    info.FileName = ReadResult(1) 'Open the application
    
                    Dim myProcess As New System.Diagnostics.Process
                    myProcess.StartInfo = info
                    myProcess.Start() 'Start the process
                    myProcess.WaitForExit() 'Wait until the process started is finished
                    myProcess.Close() 'Release the resources
                    Label5.Text = "Install Complete..."
                    Label5.Refresh()
                    System.Threading.Thread.Sleep(750)
                    Label5.Text = ""
                    Label5.Refresh()
    
    
                Else
                    MessageBox.Show("Something is wrong! File = " & ReadResult(1))
                End If
    
                line = stream_reader.ReadLine() 'Move on to the next line.
            Loop
            stream_reader.Close()
    
            ' We'll assume you have all the filepaths in a listbox
            ' it would work the same for any other collection type
    
            pCount = ListBox1.Items.Count
            ReDim p(pCount - 1)
    
            For i = 0 To pCount - 1
                p(i) = New Process With {.EnableRaisingEvents = True}
                AddHandler p(i).Exited, AddressOf ProcessExit
                p(i).StartInfo.FileName = ListBox1.Items(i).ToString
                p(i).Start()
            Next
    
        End Sub
    
        Private Sub ProcessExit(ByVal sender As Object, ByVal e As System.EventArgs)
    
            pCount -= 1
            If pCount = 0 Then
                MsgBox("All Done")
            End If
    
        End Sub
    End Class-
    with ur code......
    No not at all, I am saying use my code and place it into your so you can pass the status of your chk boxes to your other form.
    Although I feel like I mis understood your question

    My Understanding:

    You have a form with a list of items to install. The user selects what items he wants installed and you want to know how to get that list of checked items to your other installer form?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    Hmmmm... Is there a way to read the last column in the listview?

    As i have the file location in a column......

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    Can i do:
    Code:
    For Each App In SelectPrograms.App_List.Items(3).SubItems.ToString
         '//Install App
    Next
    i'm assuming columns start at 0

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    Anyone?

  9. #9
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: Passing checked items/process to other form

    You can specify which sub item it is by the name of the colum like so

    vb.net Code:
    1. ListView1.Items(3).SubItems("Name of colum")

    So in that case it will return the value of the column specified of item 3.

    If you are trying to get all the items in that colum you can do this
    vb.net Code:
    1. For Each item As ListViewItem In ListView1.Items
    2.  
    3.             item.SubItems("Name of colum").ToString()
    4.  
    5.  
    6.         Next

    EDIT: Let me double check this, I am more farmiliar with datagridview, but they seem very similar
    Last edited by Crzyrio; May 9th, 2013 at 09:59 AM.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    OK I shall try.......

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    Ok i think that would work, now how would I pass checked items?

  12. #12
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: Passing checked items/process to other form

    Quote Originally Posted by chris-2k View Post
    Ok i think that would work, now how would I pass checked items?
    What exactly do you want to pass?

    Your list view contains check boxes, and for every box checked you want to pass what is contained in those rows?

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    I need to pass listview items (checked items) to Form2 and then start the process.....

    I've got (form1, pass items):

    If App_List.CheckedItems.Count > 0 Then
    For Each Item As ListViewItem In App_List.CheckedItems
    'Need to pass checked items to the install form, but how ?
    Next
    Me.Hide()
    InstallPrograms.Show()
    Else
    MessageBox.Show("Nothing selected to install!")
    End If

    And (form2, to start the process):

    For Each App In SelectPrograms.App_List.Items(3).SubItems.ToString
    Label3.Refresh()
    Label5.Refresh()
    Dim info As New System.Diagnostics.ProcessStartInfo
    info.FileName = App

    'ReadResult(1) Open the application

    Dim myProcess As New System.Diagnostics.Process
    myProcess.StartInfo = info
    myProcess.Start() 'Start the process
    myProcess.WaitForExit() 'Wait until the process started is finished
    myProcess.Close() 'Release the resources
    Label5.Text = "Install Complete..."
    Label5.Refresh()
    System.Threading.Thread.Sleep(750)
    Label5.Text = ""
    Label5.Refresh()

    line = stream_reader.ReadLine() 'Move on to the next line.
    Next

    I have the file location in the last column..

  14. #14
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: Passing checked items/process to other form

    Since you are just hiding the first form, you should be able to simply do this in form2

    vb.net Code:
    1. Form1.App_List.CheckedItems

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Passing checked items/process to other form

    Ok i've come up with:
    Code:
    For Each App As ListViewItem In SelectPrograms.App_List.CheckedItems
                Label3.Text = "wooork" + App.SubItems(0).Text
                Label3.Refresh()
                Label5.Refresh()
    
                Dim p As New System.Diagnostics.Process
                p = App.SubItems(3).Text
    
                Dim myProcess As New System.Diagnostics.Process
                myProcess.StartInfo = p
                myProcess.Start() 'Start the process
                myProcess.WaitForExit() 'Wait until the process started is finished
                myProcess.Close() 'Release the resources
                Label5.Text = "Install Complete..."
                Label5.Refresh()
                System.Threading.Thread.Sleep(750)
                Label5.Text = ""
                Label5.Refresh()
           .Next
    but 1 error, can ya help?

    Error 1 Value of type 'String' cannot be converted to 'System.Diagnostics.Process'. H:\X17-59183\PostInstall\PostInstall\InstallPrograms.vb 25 17 PostInstall

  16. #16
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: Passing checked items/process to other form

    Quote Originally Posted by chris-2k View Post
    Ok i've come up with:
    Code:
    For Each App As ListViewItem In SelectPrograms.App_List.CheckedItems
                Label3.Text = "wooork" + App.SubItems(0).Text
                Label3.Refresh()
                Label5.Refresh()
    
                Dim p As New System.Diagnostics.Process
                p = App.SubItems(3).Text
    
                Dim myProcess As New System.Diagnostics.Process
                myProcess.StartInfo = p
                myProcess.Start() 'Start the process
                myProcess.WaitForExit() 'Wait until the process started is finished
                myProcess.Close() 'Release the resources
                Label5.Text = "Install Complete..."
                Label5.Refresh()
                System.Threading.Thread.Sleep(750)
                Label5.Text = ""
                Label5.Refresh()
           .Next
    but 1 error, can ya help?

    Error 1 Value of type 'String' cannot be converted to 'System.Diagnostics.Process'. H:\X17-59183\PostInstall\PostInstall\InstallPrograms.vb 25 17 PostInstall


    it is because of this line

    vb.net Code:
    1. Dim p As New System.Diagnostics.Process
    2.             p = App.SubItems(3).Text

    You are saying that your process is = to a line of text. What are you trying to do there?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width