本文介绍了从数据库绑定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:

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

10-24 07:16