为什么GridLookUpEdit显示[EditValue为null]

时间:2013-04-03 17:28:05

标签: c# devexpress xtratreelist gridlookupedit

我有一个DataTable作为GridLookUpEdit的数据源。

  private void MachineTreeCellEdit(object sender, GetCustomNodeCellEditEventArgs e) {
     Contract.Assume(sender != null, "sender is null.");
     Contract.Assume(e != null, "e is null.");

     if (e.Node != null) {
        var element = e.Node.GetValue(0) as XElement;
        if (element == null) {
           // no element object
           return;
        }

        if (element.Name.LocalName == "host" && e.Column.Name == "machineViewGroups") {
           GridLookUpEdit lookup = new GridLookUpEdit();
           lookup.Properties.DisplayMember = "Name";
           lookup.Properties.ValueMember = "Name";
           lookup.Properties.DataSource = GetLookupDataSource(element);
           lookup.Properties.PopulateViewColumns();

           e.RepositoryItem = lookup.Properties;
        }
     }
  }

  private DataTable GetLookupDataSource(XElement element) {
     var configsTable = new DataTable("Configurations");
     configsTable.Columns.AddRange(new DataColumn[] { 
        new DataColumn("Name", typeof(string)),
        new DataColumn("Version", typeof(string))
     });

     var groupAncestor = element.Ancestors("group").First();
     var configOptions = Presenter.Repository.Root
                                  .Elements("group")
                                  .Where(el => el.Attribute("name").Value == groupAncestor.Attribute("name").Value)
                                  .SelectMany(el => el.Descendants("cfg"))
                                  .ToList();

     for (int option = 0; option < configOptions.Count; option++) {
        var newRow = configsTable.NewRow();
        newRow["Name"] = configOptions[option].Attribute("name").Value;
        newRow["Version"] = configOptions[option].Element("version").Value;
        configsTable.Rows.Add(newRow);
     }

     configsTable.AcceptChanges();

     return configsTable;
  }

虽然我有一个用行创建的数据表,为什么GridLookUpEdit始终显示[EditValue is null] 而不是数据表中的数据

此外,当我点击下拉箭头时,弹出窗口不会显示。那会告诉我数据源是空的。但是,我验证了数据表中有我期望的数据。

0 个答案:

没有答案