从数据库绑定DevExpress Treelist中的数据 [英] Binding data in DevExpress Treelist from database

查看:554
本文介绍了从数据库绑定DevExpress Treelist中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我有一个 UserControl 名为SubControl。在该用户控件中,该控件包含 TreeList 和两个 Button 。用于聚焦树状列表的下一行和上一行的按钮。

In my project i have a UserControl named SubControl. In that UserControl which contains TreeList and two Button. the button used to focus the next and previous row of the treelist.

在另一个项目中,我还有一个名为MainControl的UserControl各种控件,这里我使用的是SubControl。

In another project I have another UserControl named MainControl various controls and Here i'm using the SubControl.

我的问题是,从MainControl我无法将数据从数据库绑定到树列表中。

What my problem is, From MainControl i can't able to bind the data into the treelist from the database.

SqlConnection SqlCon = new SqlConnection("Data Source=source; Initial Catalog=dbname; Integrated Security=True");
        SqlCon.Open();
        SqlCommand ad = new SqlCommand("Select* from mytablename", SqlCon);
        SqlDataAdapter da = new SqlDataAdapter(ad);
        DataSet ds = new DataSet();

        da.Fill(ds);

        SubControl.DataSource = ds; 
        SubControl.DataBindings();

我如何实现这一目标。帮助表示赞赏

How can i achieve this. Helps appreciated

推荐答案

您必须绑定到DataTable,而不是数据集。

You have to bind to the DataTable, not the DataSet.

SubControl.DataSource = ds.Tables[0];

来自DevExpress:

From DevExpress:

https://www.devexpress.com/Support/Center/Question/Details/Q520794


要创建树形列表的层次结构,必须指定另外两个字段源数据表中的 strong>。
第一个字段必须存储节点的唯一ID(在大多数情况下,
已经是DataTable中的主键)。另一个字段
必须包含每个节点的父节点ID。要为TreeList控件指定这些字段
,请使用TreeList.KeyFieldName和
TreeList.ParentFieldName属性。有关这方面的更多信息,请参考以下
帮助文章:XtraTreeList中的树生成
算法。

In order to create the tree list hierarchical structure, it's necessary to specify two additional fields in the source DataTable. The first field must store the nodes' unique IDs (in most cases, there is already a primary key in the DataTable). The other field must contain the parent node's ID for each node. To specify these fields for the TreeList control, use the TreeList.KeyFieldName and TreeList.ParentFieldName properties. Please refer to the following help article for more information in this regard: Tree Generation Algorithm in the XtraTreeList.

这篇关于从数据库绑定DevExpress Treelist中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆