我尝试在我的TreeList中显示一个组合框代码:
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;
但是,组合仍为空,显示“[无数据]”。当我在我的数据源上设置断点时,我看到数据源已填满。
我做错了什么?
答案 0 :(得分:1)
您的大部分代码看起来都不错,所以我怀疑它可能是缺少的字段名或数据源的某些问题。
以下是一个很小的示例,其中大部分是您的代码的直接副本(略微缩进),但我在运行时创建了树形图,并创建了一个示例通用列表,用作测试它的数据源。
在构造函数的末尾,对于未绑定模式,我向树中添加了几个节点,否则我绑定到数据源并在permissionColumn上设置fieldname。
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; }
}
答案 1 :(得分:0)
这是因为您将列设置为Unbound
...
permissionColumn.UnboundType = UnboundColumnType.Object;
...
答案 2 :(得分:0)
我刚回去查看了查找编辑器 - 我非常确定您需要在任何数据出现之前手动创建列。 DevExpress LookupEditor不是一个简单的下拉菜单,它基本上是一个嵌入式网格控件。如果要显示的项目列表中只有一个属性,则可能是这样的:
rep.Columns.Add(new LookupColumnInfo("PropertyName", 0));