当前位置:编程学习 > C#/ASP.NET >>

winform--comboBox新手求救!!!

比如说我想将c:/123/这个文件夹下面的文件名全部便利出来,存到comboBox里,如何操作。。。求大神指教啊!!! --------------------编程问答--------------------
comboBox.DataSource = Directory.GetFiles("c:/123/");
--------------------编程问答-------------------- 1.先读取文件;
2.将读出来的内容循环添加到comboBox控件的item. --------------------编程问答-------------------- 遍历Directory.GetFiles的返回数组,或绑定 --------------------编程问答-------------------- 引用下IO类
取到该文件夹下的所有Files循环给comboBox邦上去 --------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsComboBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //获得目录下的文件
            string[] files = Directory.GetFiles("E:\\TF");
            //循环文件
            foreach (string file in files)
            {
                comboBox1.Items.Add(file);
            }
        }
    }
}

补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,