DevExpress Combobox in treelist is disabled
I try to show a combobox in my TreeList usiong this code:
RepositoryItemLookUpEdit rep = new RepositoryItemLookUpEdit();
rep.TextEditStyle = TextEditStyles.DisableTextEditor;
//rep = new RepositoryItemComboBox();
//rep.Items.AddRange(new SecuredObject<QuestionnaireCategory>().PermissionType);
//rep.Items.AddRange(new object[] { "A", "B", "C" });
treeList1.RepositoryItems.Add(rep);
TreeListColumn disciplineColumn = treeList1.Columns.Add();
disciplineColumn.Caption = "Discipline";
disciplineColumn.Visible = true;
disciplineColumn.FieldName = "Entity.Description";
disciplineColumn.OptionsColumn.AllowEdit = false;
TreeListColumn permissionColumn = treeList1.Columns.Add();
permissionColumn.Caption = "Permissie";
permissionColumn.Visible = true;
permissionColumn.Name = "Permission";
//permissionColumn.FieldName = "PermissionType";
permissionColumn.UnboundType = UnboundColumnType.Object;
permissionColumn.ColumnEdit = rep;
//permissionColumn.OptionsColumn.ReadOnly = false;
//permissionColumn.OptionsColumn.AllowEdit = true;
rep.DataSource = permissions;
rep.DisplayMember = "Description";
rep.ValueMember = "Id";
rep.Name = "ola";
rep.ThrowExceptionOnInvalidLookUpEditValueType = true;
开发者_JS百科
However, the combo remains empty, it displays '[no data]'. When I set a breakpoint at my datasource, I see that the datasource is filled.
What am I doing wrong?
Most of your code looks ok, so I suspect it maybe either the missing fieldname or some problem with the datasource.
The following is a tiny sample, most of which is a straight copy of your code (slightly indented) , but I am creating the treelist at runtime and have created a sample generic list to use as a datasource to test it.
At the end of the constructor, for unbound mode , I add a few nodes to the tree otherwise I bind to the datasource and set the fieldname on permissionColumn.
using System;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraTreeList.Data;
public class Form1 : Form
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.ClientSize = new System.Drawing.Size(700, 500);
DevExpress.XtraTreeList.TreeList treeList1 = new DevExpress.XtraTreeList.TreeList();
this.Controls.Add(treeList1);
treeList1.Dock = DockStyle.Fill;
var permissions = new System.Collections.Generic.List<TestClass>();
permissions.Add(new TestClass() { Id = 1 , Description = "Permission 1" });
permissions.Add(new TestClass() { Id = 99, Description = "Permission 99" });
var list = new System.Collections.Generic.List<TestClass2>();
list.Add(new TestClass2() { Id = 1 , PermissionId = 1 , Description2 = "List Desc 1" });
list.Add(new TestClass2() { Id = 2 , PermissionId = 99, Description2 = "List Desc 2" });
// Your code
RepositoryItemLookUpEdit rep = new RepositoryItemLookUpEdit();
rep.TextEditStyle = TextEditStyles.DisableTextEditor;
//rep = new RepositoryItemComboBox();
//rep.Items.AddRange(new SecuredObject<QuestionnaireCategory>().PermissionType);
//rep.Items.AddRange(new object[] { "A", "B", "C" });
treeList1.RepositoryItems.Add(rep);
TreeListColumn disciplineColumn = treeList1.Columns.Add();
disciplineColumn.Caption = "Discipline";
disciplineColumn.Visible = true;
disciplineColumn.FieldName = "Entity.Description";
disciplineColumn.OptionsColumn.AllowEdit = false;
TreeListColumn permissionColumn = treeList1.Columns.Add();
permissionColumn.Caption = "Permissie";
permissionColumn.Visible = true;
permissionColumn.Name = "Permission";
//permissionColumn.FieldName = "PermissionType";
permissionColumn.UnboundType = UnboundColumnType.Object;
permissionColumn.ColumnEdit = rep;
//permissionColumn.OptionsColumn.ReadOnly = false;
//permissionColumn.OptionsColumn.AllowEdit = true;
rep.DataSource = permissions;
rep.DisplayMember = "Description";
rep.ValueMember = "Id";
rep.Name = "ola";
rep.ThrowExceptionOnInvalidLookUpEditValueType = true;
// End Your code
disciplineColumn.FieldName = "Description2";
bool unBoundMode = false;
if (unBoundMode)
{
treeList1.AppendNode(new object[] { "Item1", 1 }, -1);
treeList1.AppendNode(new object[] { "Item2", 99 }, -1);
}
else
{
treeList1.DataSource = list;
permissionColumn.FieldName = "PermissionId";
}
}
}
public class TestClass
{
public int Id { get; set; }
public string Description { get; set; }
}
public class TestClass2
{
public int Id { get; set; }
public int PermissionId { get; set; }
public string Description2 { get; set; }
}
It's that because your setting the column as Unbound
...
permissionColumn.UnboundType = UnboundColumnType.Object;
...
I just went back and checked out Lookup Editors -- I'm pretty sure you need to create columns manually before any data will appear. The DevExpress LookupEditor isn't a simple drop-down, it's basically an embedded grid control. If there's only one property on your item list to display, it would be something like this:
rep.Columns.Add(new LookupColumnInfo("PropertyName", 0));
精彩评论