Populating variables from DataGridView selections

Nucleus

Active member
Joined
May 24, 2005
Messages
30
Programming Experience
Beginner
vb.net has a steep learning curve, so please bare with me.

I am trying to create a program where you can select multiple Linux hosts, then select a bash script (which already exists on the Linux hosts), and click a button to execute the script on all the hosts. I've managed to get vb.net to read from XML files, and list all the available commands and all the available hosts. I've also found a way to connect on a host using Renci.SshNet.

What I need to do now, is configure a button, to see which hosts I have selected, and which bash script I have selected, and run the script on those hosts.

This is the GUI.
gui.png

And this is the code
VB.NET:
Public Class SSHCommander
    Dim cmd As Renci.SshNet.SshCommand
    Dim hostsPath As String = "hosts.xml"
    Dim commandsPath As String = "commands.xml"
    Dim connInfo As New Renci.SshNet.PasswordConnectionInfo("hostname", "22", "user", "pass")
    Private Sub SSHCommander_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CommandsDataSet.ReadXml(commandsPath)
        CommandsGridView.DataSource = CommandsDataSet
        CommandsGridView.DataMember = "commands"
        HostsDataSet.ReadXml(hostsPath)
        HostsGridView.DataSource = HostsDataSet
        HostsGridView.DataMember = "hosts"
    End Sub
    Private Sub execute_command_Click(sender As Object, e As EventArgs) Handles execute_command.Click
        Dim sshClient As New Renci.SshNet.SshClient(connInfo)
        Using sshClient
            sshClient.Connect()
            cmd = sshClient.RunCommand("selected command must be here")
            rtbresult.Text = cmd.Result
            sshClient.Disconnect()
        End Using
    End Sub
End Class

Basically, the "connInfo" variable fields must be populated by the "Hosts" DataGridView selection on the GUI, and the "sshClient.RunCommand" fields must be populated by the "Commands" DataGridView selection on the GUI. Another problem I must solve, is how do I handle multiple hosts selections?
 
A little help:
For Each row As DataGridViewRow In CommandsDataGridView.SelectedRows
    Dim data = CType(row.DataBoundItem, DataRowView)
    Dim value = data("Hostname")

Next
 
Back
Top