匹配枚举与组合框列表似乎不起作用

时间:2017-02-16 11:26:41

标签: c# .net combobox enums

[更新:添加了<RichTextBlock FontSize="36"> <Paragraph FontFamily="Palatino Linotype"> 2<Run Typography.Variants="Superscript">3</Run> 14<Run Typography.Variants="Superscript">th</Run> </Paragraph> <Paragraph FontFamily="Palatino Linotype"> H<Run Typography.Variants="Subscript">2</Run>O Footnote<Run Typography.Variants="Subscript">4</Run> </Paragraph> </RichTextBlock> 构造函数]

我正在尝试将某些clases中的某些数据与windows窗体应用程序中的组合框值进行匹配。

到目前为止我所做的事情看起来像这样:

(此类有一些Form1()值我想要存储在组合框中,具体取决于region[]

enum Project

下一个类存储某个模式文件

public Form1()
{
    formatWorker.DoWork += worker_DoWork;
    formatWorker.RunWorkerCompleted += worker_RunWorkerCompleted;

    extractWorker.DoWork += extractWorker_DoWork;
    extractWorker.ProgressChanged += extractWorker_ProgressChanged;
    extractWorker.RunWorkerCompleted += extractWorker_RunWorkerCompleted;

    InitializeComponent();
    projectBox.DataSource = Constant.projects.ToString(); 
    projectBox.SelectedIndex = (int)Regions.Project.NBTevo;
    PopulateUsbDevices();
}

class Regions
{
    public enum Project
    {
        NBT = 0,
        NBTevo = 1,
        MGU = 2
    }

    string[] regions = { "ARG", "AUSNZ", "ECE", "IND", "ISR", "LA", "ME", "NA", "NAF", "NANT", "PAL", "SEA", "TC", "ZA" };

    public string[] GetRegionsForProject(Project proj)
    {
        //all directories from /Databases/proj[i]
        string[] allDirectories = Constant.ExtractFileNames(Directory.GetDirectories(Constant.path + "//" + Constant.projects[(int)proj]));


        string[] availableSubDirectories = Enumerable.Intersect(allDirectories, regions).ToArray();

        return availableSubDirectories;
    }
}

我正在尝试构建依赖项,例如,根据class DBVersion { public string[] GetVersion(string proj, string region) { string pattern = "^" + proj + "_" + region + "_" + @"(\d+\.\d+\.\d+_[a-zA-Z0-9_]+)\.iso$"; string[] files = Directory.GetFiles(Constant.path + "\\" + proj + "\\" + region + "\\images\\", "*.iso", SearchOption.AllDirectories); return files; } } projectBox中的选定值,某些版本将显示在regionBox

versionBox

运行后,我private void projectBox_SelectedIndexChanged(object sender, EventArgs e) { isoPaths.Clear(); populateRegions((Regions.Project)Enum.Parse(typeof(Regions.Project), projectBox.SelectedValue.ToString())); regionBox.SelectedIndex = 0; regionBox_SelectedIndexChanged(null, null); } private void regionBox_SelectedIndexChanged(object sender, EventArgs e) { string[] versionPaths = version.GetVersion(projectBox.SelectedValue.ToString(), regionBox.SelectedItem.ToString()); isoPaths.Clear(); isoPaths.AddRange(versionPaths); populateVersions(Constant.ExtractFileNames(versionPaths)); //versionBox.SelectedIndex = 0; //versionBox_SelectedIndexChanged(null, null); } private void versionBox_SelectedIndexChanged(object sender, EventArgs e) { } private void populateRegions(Regions.Project proj) { this.regionBox.DataSource = region.GetRegionsForProject(proj); } private void populateVersions(string[] versions) { this.versionBox.DataSource = version.GetVersion( projectBox.SelectedItem.ToString(), region‌​Box.SelectedItem.ToS‌​tring()); }

中没有任何内容

1 个答案:

答案 0 :(得分:1)

如果您想将DataSource绑定到ComboBox,则应使用:

  

实现IList接口或数组

的对象

根据ComboBox.DataSource Property documentation

所以Form1的构造函数中的这一行:

projectBox.DataSource = Constant.projects.ToString();

必须改为:

projectBox.DataSource = Constant.projects;

其余的组合框是空的,因为问题从一个级联到另一个级联。如果一个是空的,则其余部分无法正确填充