【问题标题】:Programmatically create hierarchy in telerik radgridview winforms以编程方式在 Telerik radgridview winforms 中创建层次结构
【发布时间】:2013-02-06 17:12:00
【问题描述】:

我想在未绑定数据的 radgridview 中创建层次结构。到目前为止,我还没有弄清楚该怎么做。

我想你可以这样做:

Grid.Parent.Rows.Add(new object[] {});

Grid.Parent.Child.Rows.Add(new object[] {});

但我没有这样的运气。网格不能是数据绑定的。我有一个数据列表,我将遍历并创建层次结构。

我需要知道如何为该父节点创建父节点和子节点。我看到了模板并把它们弄乱了,但我只能让它与数据源一起工作。

有人能指出正确的方向吗?

【问题讨论】:

    标签: winforms c#-4.0 telerik radgridview


    【解决方案1】:

    看看这篇文章中的第二部分Binding to Hierarchical Data Programmatically

    【讨论】:

    • 我发现这些 Telerik 控件难以使用。在让它工作之前,我不得不多次处理关系和模板。我终于可以通过在 Telerik 网站上观看演示视频来让它工作
    • 一旦您了解了细节,就可以轻松地使用该套件。模板是不同的层次结构级别,而关系是所需模板之间的关系。
    【解决方案2】:

    //数据绑定radgridview的代码

     void DataBInd()
            {
    
                var Source = Results.GetData(FromDate, Todate, drpLedger.Value);
                radGridLedgerAccount.DataSource = null;
                radGridLedgerAccount.DataSource = Source;
                FormatGrid();
                BindChildView();
                BindBarCharView(Source);
            }
    

    //绑定子视图的代码,即层次结构

      void BindChildView()
            {
                if (drpLedger.Value != null)
                {
    
    
                    GridViewTemplate childview = new GridViewTemplate();
                    childview.Caption = "Details";
                    childview.DataSource = null;
                    childview.DataSource = Source;
                    this.radGridLedgerAccount.MasterTemplate.Templates.Add(childview);
    
                    FormatChildView(childview);
                    GridViewRelation relation = new GridViewRelation(this.radGridLedgerAccount.MasterTemplate);
                    relation.ChildTemplate = childview;
                    relation.ParentColumnNames.Add("months");
                    relation.ChildColumnNames.Add("NameOfMonth");
                    this.radGridLedgerAccount.Relations.Add(relation);
    
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      相关资源
      最近更新 更多