简体   繁体   English

如何在vb.net中为数组设置新属性?

[英]How to set a new property for an array in vb.net?

Dim SteamGames As New Dictionary(Of String, String)
For Each Game As String In System.IO.Directory.GetDirectories(Me.tb_SteamDir.Text)
    SteamGames.Add(Game, System.IO.Path.GetFileName(Game))
Next Game

For Each Pair As KeyValuePair(Of String, String) In SteamGames
    dgv_Table.Rows.Add(Pair.Key)
    dgv_Table.Rows.Add(Pair.Value)
Next Pair

I am getting both the folder directory and the folder's name in the same column, how do I make them separate into different columns? 我在同一列中同时获得了文件夹目录和文件夹名称,如何将它们分成不同的列?

This should load the ComboBox and the DataGridView as you requested: 这应该按照您的要求加载ComboBox和DataGridView:

    Dim DT As New DataTable
    DT.Columns.Add("Full Path")
    Dim GameNames_Master As New List(Of String)
    For Each Dir As DirectoryInfo In New DirectoryInfo(Me.tb_SteamDir.Text).GetDirectories
        GameNames_Master.Add(Dir.Name)
        DT.Rows.Add(New Object() {Dir.FullName})
    Next Dir
    dgv_Table.DataSource = DT
    Me.cb_Games.DataSource = GameNames_Master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM