添加项目到组合框 [英] Add Items to combobox

查看:59
本文介绍了添加项目到组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件夹Letters中的所有文件名添加到我的组合框中,如下代码:

ComboBox3.Items.Add(FileIO.FileSystem.GetName(My.Application.Info.DirectoryPath& \ Letters\test))

但是这段代码只是将test添加到我的组合框中,但我想添加文件夹Letters中的所有文件名。

我只想要文件名。

给我一些例子。

请帮助我。

谢谢。

I want to add all file names from folder"Letters" to my combobox like this code:
ComboBox3.Items.Add(FileIO.FileSystem.GetName(My.Application.Info.DirectoryPath & "\Letters\test"))
But this code just add "test" to my combobox but I want to add all file names from folder "Letters".
I want just file names.
Give me some examples.
Please help Me.
Thank You.

推荐答案

信用ThePhantomUpvoter,其评论指向正确的方法...



您使用过 .GetName 正确返回文件夹的名称。



如果你想要文件名,你需要使用 .GetFiles 例如
With credit to ThePhantomUpvoter whose comment is pointing you to the correct method...

You have used .GetName which is correctly returning the name of the folder.

If you want the filenames you need to use .GetFiles for example
For Each f As String In FileIO.FileSystem.GetFiles(My.Application.Info.DirectoryPath & "\Letters\test"))
            ComboBox1.Items.Add(f)
        Next









这是获取文件名的第一部分的一种(笨重)方式





Here is one (clunky) way of getting just the first part of the filename

For Each f As String In FileIO.FileSystem.GetFiles("c:\\develop")
    Dim s() As String
    s = f.Split(New Char() {".", "\\"})
    ComboBox1.Items.Add(s(s.GetUpperBound(0) - 1))
Next


这篇关于添加项目到组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆