2015-07-03 24 views
0

所以我試圖從一個目錄加載文件名,並將它們設置爲一個checkList框,但該框始終保持空白,爲什麼這可能是任何想法?CheckBoxList數據源不會在Program Launch中設置。

請參閱下面的代碼。

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()); 
      } 

回答

0

,而不是作爲一個數據源迭代通過查詢添加和補充。

foreach (var variable in fileQuery) 
{ 
    chkListBox.Items.Add(variable); 
} 
-1

chkListBox.DataBind(); 

下面

chkListBox.DataSource = fileQuery.ToArray(); 
+0

我沒有爲'chkListBox.DataBind()的選項;' – Nim

+0

如果它使不同的這是一個.NET 4 WF應用。 – Nim

相關問題