I have a DataTable
as a data source for a 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;
}
Although I have a data table created with rows, why is the GridLookUpEdit
always displaying [EditValue is null]
instead of the data in the data table?
Additionally, when I click on the drop-down arrow, the pop-up does not display. That would tell me that the data source is empty. However, I validated the data table has data that I expect.