打开添加到组合框的文件

时间:2016-12-11 19:28:03

标签: vb.net

Dim dir = "..//Football/"
Private Sub FTablebutton_Click(sender As Object, e As EventArgs) Handles FTablebutton.Click

    For Each file As String In System.IO.Directory.GetFiles(dir)
        FfilesComboBox.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
    Next

End Sub

Private Sub FfilesComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FfilesComboBox.SelectedIndexChanged
    Dim openfile As String = System.IO.Path.Combine(dir, FfilesComboBox.SelectedItem.ToString)
    'start the process using the openfile string
    Process.Start(openfile)
End Sub

我可以将所有文件添加到组合框中,但问题是我从组合框中选择时无法打开文件

2 个答案:

答案 0 :(得分:1)

试试这个

  Polymer({
    is: 'dramatic-view',
    attached: function () {
      this._observer = Polymer.dom(this.$.contentNode).observeNodes(function (info) {
        console.log('kromid info', info);
      });
    }
  });

答案 1 :(得分:0)

如果您然后使用Visual Studio 2008或更新版本。您可以使用Anonymous类存储FileNameWithoutExtension的完整文件路径。

    Dim dir = "..//Football/"

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        FfilesComboBox.DisplayMember = "Text"

End Sub

Private Sub FTablebutton_Click(sender As Object, e As EventArgs) Handles FTablebutton.Click

    For Each file As String In System.IO.Directory.GetFiles(Dir)
        FfilesComboBox.Items.Add(New With {.Text = System.IO.Path.GetFileNameWithoutExtension(file), .Value = file})
    Next

End Sub

您可以使用ComboBox1.SelectedItem.Value获取值(即文件完整路径)

Private Sub FfilesComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FfilesComboBox.SelectedIndexChanged

    'start the process using the openfile string
    Process.Start(FfilesComboBox.SelectedItem.Value)
End Sub

即使您选择循环子目录,这也会有效。

此代码经过测试并正常运行