0

所以我试图从目录加载文件名并将它们设置为一个复选框,但是该框始终保持空白,任何想法为什么会这样?

请看下面的代码。

static void Main( string[] args )
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var launchArg = args.FirstOrDefault( arg => !arg.StartsWith( "-" ) );
            launchArg = @"Apollo";
            if (!String.IsNullOrEmpty(launchArg))
            {
                var configID = launchArg;

                var configuration = AdrConfigurationManager.AdrSettings.Cast<AdrConfigurationElement>().SingleOrDefault(c => String.Equals(c.ID, configID, StringComparison.CurrentCultureIgnoreCase));
                if (configuration == null) throw new ArgumentException(String.Format("Could not find the configuration with ID={0}.", configID));

                // Search for the files.
                DirectoryInfo dirinfo = new DirectoryInfo(@"C:\SVNRepositiory\BMSConsulting\Common\ADR\Client Scripts\" + configuration.ID);
                var fileQuery =
                    from FileInfo fileinfo in dirinfo.GetFiles()
                    orderby fileinfo.Name.Substring(0, 1) ascending
                    select fileinfo.Name;
                // Add files to checkbox. 
                var chkListBox = new CheckedListBox();
                chkListBox.DataSource = fileQuery.ToArray();
                for (int i = 0; i < chkListBox.Items.Count; i++)
                    chkListBox.SetItemChecked(i, true);
                var progress = new AdrProgress(configuration, chkListBox);
                progress.Show();

                Application.Run( progress );
            }
            else
            {
                Application.Run(new ADR());   
            }
4

2 回答 2

0

而不是 add 作为数据源遍历查询并添加。

foreach (var variable in fileQuery)
{
    chkListBox.Items.Add(variable);
}
于 2015-07-06T10:34:47.760 回答
-1

chkListBox.DataBind();

以下

chkListBox.DataSource = fileQuery.ToArray();
于 2015-07-03T15:17:32.990 回答