-2

我知道这是一个非常普遍且存在的问题,但是我从这里尝试了许多解决方案,但我一直遇到同样的错误。

请让我知道错误在哪里:(如果我遗漏任何信息,请编辑/建议

代码:XAML:

 <DataGrid Name="dtgQCNumbers"  
                              Width="409"
                              AutoGenerateColumns="False" 
                              ItemsSource="{Binding Path=.}"
                              CanUserResizeColumns="True" 
                              SelectionChanged="dtgQCNumbers_SelectionChanged" 
                              >

                          <DataGrid.Columns>
                            <DataGridCheckBoxColumn Header="IsChecked" Width="100" 
                                                                         Binding="{Binding Path=IsActive}"
                                                                        CanUserResize="True"/>                                 

                                                <DataGridTextColumn Header="QC_ID" Width="100" 
                                                                    Binding="{Binding Path=DataGridTextBox_QCList1}"
                                                                    CanUserResize="True"/>

                                                <DataGridTextColumn Header="Summary" Width="100"
                                                                    Binding="{Binding Path=DataGridTextBox_QCSummary}"
                                                                    CanUserResize="True"/>

                                                <DataGridComboBoxColumn Header="ControlOption" Width="100"
                                                                        SelectedItemBinding="{Binding Path=DataGridComboxBox_Control}"
                                                                        ScrollViewer.CanContentScroll="True"
                                                                        ScrollViewer.VerticalScrollBarVisibility="Auto"
                                                                        IsReadOnly="True"
                                                                        CanUserResize="True">
                                                <DataGridComboBoxColumn.ItemsSource>
                                                        <col:ArrayList>
                                                            <sys:String>AVS</sys:String>
                                                            <sys:String>DB</sys:String>
                                                                  <sys:String>AVS_DB</sys:String>
                                                        </col:ArrayList>
                                                    </DataGridComboBoxColumn.ItemsSource>

                                                </DataGridComboBoxColumn>

                        </DataGrid.Columns>
                         grid.ColumnWidth = new DataGridLength(100);

</DataGrid>

数据绑定背后的代码是:

private void OnInitialized()
  {
      string projectName = null;
      string crNumber = null;
      ComboBoxItem selectedProject;
      selectedProject = (ComboBoxItem)ddlProject.SelectedItem;
      projectName = selectedProject.Content.ToString();

      ActiveDirectoryWrapper.ApplicationUserData userData = Common.GetUserData(userName);

      string queryString;
      if (rdoMyQCs.IsChecked == true)
      {
          queryString = "Blalalalala";
      }
      else
      {
          queryString = "Blahblah";
      }

      Recordset qcIdSet = Common.queryTestDirector(projectName, queryString);
      qcIdSet.First();
      string colname = qcIdSet.get_ColName(0);

      _ds = new DataSet();
      DataTable table = new DataTable();
      _ds.Tables.Add(table);

      DataColumn c1 = new DataColumn("IsChecked", typeof(bool));
      table.Columns.Add(c1);
      DataColumn c2 = new DataColumn("QC_ID", typeof(string));
      c2.MaxLength = 500;
      table.Columns.Add(c2);
      DataColumn c3 = new DataColumn("QC_Summary", typeof(string));
      c3.MaxLength = 500;
      table.Columns.Add(c3);
      DataColumn c4 = new DataColumn("Control Option", typeof(string));
      c4.MaxLength = 500;
      table.Columns.Add(c4);
      while (!qcIdSet.EOR)
      {
          DataRow rw = table.NewRow();
          rw["IsChecked"] = true;
          rw["QC_ID"] = qcIdSet["BG_BUG_ID"].ToString();
          rw["QC_Summary"] = "";
          rw["Control Option for Deployment"] = "AVS_DB";
          table.Rows.Add(rw);
          qcIdSet.Next();
      }

      dtgQCNumbers.DataContext = _ds.Tables[0];
      throw new NotImplementedException();
  }

我不断收到错误消息“在使用 ItemsSource 之前,项目集合必须为空”

4

1 回答 1

0

你到底为什么要string在你的DataGrid.Items.

    </DataGrid.Columns>
    grid.ColumnWidth = new DataGridLength(100);
</DataGrid>

你会得到那个错误并不奇怪......

于 2012-08-23T02:35:04.040 回答