【问题标题】:How to Bind data to Pivot grid in Winforms using c# code in Winforms?如何使用 Winforms 中的 c# 代码将数据绑定到 Winforms 中的 Pivot 网格?
【发布时间】:2018-01-22 02:42:31
【问题描述】:

我想使用非 SqlDataSource 的代码将数据绑定到透视网格。

private void Report_Summary_Load(object sender,EventArgs e)
{
    string cs= configuraitonManager.connectionString["connectionStringDatabase"].connectionString;

    using(SqlConnection con = new SqlConnection(cs))
    {
         SqlCommand cmd = new SqlCommand("spStoredProcedureTest",con);
         cmd.CommandType = CommandType.StoredProcedure;
         con.open();

        SqlDataReader sda = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        pivotGrid.DataSource = ds;

        PivotGridField Name = new PivotGridField("Name",PivotArea.RowArea);
        PivotGrid.Fields.AddRange(new PivotGridField[] {Name});

        Name.AreaIndex = 0;

        // My pivot grid name is  "pivotGridDemo"

        //How to bind the data to the data area,column area and Row area
     }
}

我有 5 个字段

姓名、标准、城市、年龄、生日

我要设置行区的姓名和城市列区的城市数据区的年龄和出生年份

更新

上面的代码是添加 Name is Row 字段。但不显示记录

【问题讨论】:

    标签: c# winforms devexpress pivot-grid


    【解决方案1】:

    试试这个:

     pivotGrid.DataSource = ds.Tables[0];
     PivotGridField fieldCity  = new PivotGridField("City", PivotArea.ColumnArea);
     fieldCity.Caption = "City";
    
     PivotGridField fieldName = new PivotGridField("Name", PivotArea.RowArea);
     fieldBureau.Caption = "Name";
    
     PivotGridField fieldCity = new PivotGridField("City", PivotArea.RowArea);
     fieldBureau.Caption = "City";
    
     PivotGridField fieldAge  = new PivotGridField("Age", PivotArea.DataArea);   
     fieldQte.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
     fieldAge.AreaIndex = 0;
     PivotGridField fieldDobYear  = new PivotGridField("DobYear ", PivotArea.DataArea);  
    
      pivotGrid.Fields.AddRange(new PivotGridField[] { fieldCity, fieldName , fieldAge  , fieldDobYear   });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-10
      • 2011-01-28
      • 2011-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2019-06-03
      相关资源
      最近更新 更多