C# winform把excel模板绑定到combobox下拉框中

比如说我现在有4个模板。全部存放在Template文件夹下,如何绑定到combobox中做到选择哪个模板就调用哪个模板

有大佬能给个Demo吗

URL:https://bbs.csdn.net/topics/600307178

帮助到你能点个采纳吗,谢谢~~,有什么问题可以继续问。

using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Linq;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //注意修改下面路径为存储Excel的目录,如果和exe在同一个目录下用  Path.Combine(Application.StartupPath, "excelfolder");

            var data = Directory.GetFiles(@"D:\文件\C#\windowform\WindowsFormsApp1\bin\Debug").Select(i => new { value = i, text = Path.GetFileName(i) }).ToList();
            comboBox1.DisplayMember = "text";
            comboBox1.ValueMember = "value";
            comboBox1.DataSource = data;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var filePath = comboBox1.SelectedValue.ToString();
            MessageBox.Show(filePath);//这里改为读取filePath指定的Excel填充数据的代码
        }
    }

}

combobox接受的是String字符串。