2010-11-10 32 views
3

我有一個水晶報表報表,我想以編程方式從c#編輯標籤。我可以操作數據源,但不能編輯標籤。如何以編程方式在水晶報表中編輯標籤?

我正在設計一個賬單報告,所以我需要顯示公司的詳細信息,日期時間和其他一些我無法從我的數據源獲得的信息。

回答

2

通常爲一個賬單,該公司的名稱和它的詳細信息(如地址等)在該法案的頂部。在這種情況下,我使用的是報告標題。在這種情況下,您可以將文本傳遞到非常容易顯示的位置。在運行時傳遞某些東西的另一種方式是使用report參數。您可以將參數綁定到字段或公式。參數也很容易傳遞。

在有一次,我用下面的代碼從動態報表中的參數,並將其綁定到GridView:

private void GetParameters() 
    { 
     //DataTable dt = new DataTable("Params"); 
     string dataTableName = "Params"; 
     //add a tablestyle to the grid so there will be custom columnstyles available 
     // after the datasource has been set.... 
     DataGridTableStyle ts = new System.Windows.Forms.DataGridTableStyle(); 
     ts.MappingName = dataTableName; 
     dtgParams.TableStyles.Add(ts); 

     // DataGridTextBoxColumn 
     DataGridTextBoxColumn cParamName = new DataGridTextBoxColumn(); 
     cParamName.MappingName = "Parameter"; 
     cParamName.HeaderText = "Parameter"; 
     cParamName.ReadOnly=true; 

     // Add the column style to the column style collection 
     ts.GridColumnStyles.Add(cParamName); 

     // DataGridTextBoxColumn 
     DataGridTextBoxColumn cType = new DataGridTextBoxColumn(); 
     cType.MappingName = "Data_Type"; 
     cType.HeaderText = "Data Type"; 
     cType.ReadOnly=true; 

     // Add the column style to the column style collection 
     ts.GridColumnStyles.Add(cType); 

     // DataGridTextBoxColumn 
     DataGridTextBoxColumn cValue = new DataGridTextBoxColumn(); 
     cValue.MappingName = "Value"; 
     cValue.HeaderText = "Value"; 
     cValue.ReadOnly=false; 

     // Add the column style to the column style collection 
     ts.GridColumnStyles.Add(cValue); 

     DataRow dr; 
     dt.Columns.Add(new DataColumn("Parameter",typeof(string))); 
     dt.Columns.Add(new DataColumn("Data_Type",typeof(string))); 
     dt.Columns.Add(new DataColumn("Value",typeof(string))); 

     // For all the Parameters defined in the report 
     for(int i=0;i<ReportDoc.DataDefinition.ParameterFields.Count; i++) 
     { 
      dr = dt.NewRow(); 
      dr[0] = ReportDoc.DataDefinition.ParameterFields[i].ParameterFieldName; 
      dr[1] = ReportDoc.DataDefinition.ParameterFields[i].ParameterValueKind; 
      dr[2] = ReportDoc.DataDefinition.ParameterFields[i].DefaultValues[0]; 
      dt.Rows.Add(dr); 
     } 
     DataView source = new DataView(dt); 
     dtgParams.DataSource = source; 
    } 

並用下面的代碼段來設置參數:

private void SetParamValue (string paramName, string paramValue) 
    { 
     ParameterFieldDefinition PFD = null; 
     ParameterValues PValues = null; 
     ParameterDiscreteValue Parm = null; 
     PValues = new ParameterValues(); 
     PFD = ReportDoc.DataDefinition.ParameterFields[paramName]; 
     Parm = new ParameterDiscreteValue(); 
     Parm.Value = paramValue; 
     PValues.Add(Parm); 
     PFD.ApplyCurrentValues(PValues); 
    } 
+0

謝謝@HananGursoy。很高興幫助你。 – Kangkan 2010-11-20 17:41:15

0

看看CR Object Model。你可以用編程方式控制什麼是有限的,但這應該有所幫助。

3

您將需要使這個給Label一個FomulaField那麼這將是通過FormulaFieldDefinitions收集訪問,您將與FormulaFieldDefinition類對象,它是對你感興趣的工作。

此外,此類公司信息等應始終直接放置在報告本身,即編輯後的RPT文件中。當談到公司的標誌時,你想特別這樣做。

+0

意思是對的。這是最簡單的解決方案。 – 2010-11-16 23:26:24

相關問題