无法获取要在自定义组合框中显示的文件名 [英] Can't get filename to display in a custom combobox

查看:73
本文介绍了无法获取要在自定义组合框中显示的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我正试图在toolStripComboBox中显示一些文件名,但遗憾的是它没有工作。

它将文件名加载到本地数据库,但数据库和DisplayMember之间的连接似乎有问题。



Hey,

I''m trying to display some file names in a toolStripComboBox but sadly enough it isn''t working.
It loads the file names in to the local database but there seems to be something wrong with the connection between the database and the DisplayMember.

string[] Filelistarray = Directory.GetFiles(@"C:\Users\a961835\Programming", "*.txt");
            DataTable dt = new DataTable();
            dt.Columns.Add("FileName");
            foreach (string FileName in Filelistarray)
            {
                DataRow dr = dt.NewRow();
                string filenameWithoutPath = Path.GetFileName(FileName);
                dr["FileName"] = filenameWithoutPath;
                dt.Rows.Add(dr);
            }

            //toolStripComboBox.ComboBox.ValueMember = "FileName";
            toolStripComboBox1.ComboBox.DataSource = dt;
            toolStripComboBox1.ComboBox.DisplayMember = "FileName";







下拉菜单combobox i ''使用来自 ButtonDropDown使用自定义控件(ButtonDropDownMenu Control) [ ^ ]



事情是这样的我添加了一个menutStripItem并在该ToolStripItem下我添加了一个toolStripComboBox只有当我尝试将文件名显示到toolStripComboBox时它才显示任何内容。



当我尝试使用普通(标准)组合框,它工作正常。





我不知道我在做什么做错了。所以任何想法都是受欢迎的。



提前致谢。



Darthillian




The dropdown menu combobox i''m using is from ButtonDropDown using Custom Control (ButtonDropDownMenu Control)[^]

The thing is that I added a menutStripItem and under that ToolStripItem I added a toolStripComboBox only when I try to display the File Names into the toolStripComboBox it s doesn''t show anything.

When I try this with the normal (standard) combobox it works just fine.


I''m not sure what i''m doing wrong. So any idea is welcome.

Thanks in advance.

Darthillian

推荐答案



你要添加行,然后按名称[FileName]设置行,直到下一行才添加。



所以如果你改变你的代码如下:



Hi,
you are adding the row, then setting the row by name [FileName], which hasn''t been added until the next line.

so if you change your code as follow:

DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
string filenameWithoutPath = Path.GetFileName(FileName);
dr["FileName"] = filenameWithoutPath;





=======================更正============ =============================



添加项目下拉菜单中的组合框





======================= Correction =========================================

To add the items in the combobox inside the drop down menu

public void SetFileNames()
{
    string[] Filelistarray = Directory.GetFiles(@"D:\Projects\VS_Test_Projects\WpfApplication1\InfragisticsTest\bin\Debug", "*.txt");
    List<string> fileNames = new List<string>();
    foreach (string FileName in Filelistarray)
    {
        string filenameWithoutPath = Path.GetFileName(FileName);
        fileNames.Add(filenameWithoutPath);
    }

    toolStripComboBox2.Items.AddRange(fileNames.ToArray());
}







问候

Jegan




Regards
Jegan


这篇关于无法获取要在自定义组合框中显示的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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