How to get runtime property in ClickEvent?

edited June 2009 in FastReport .NET
I write code like this:
    public class TestTextObject : TextObject
    {
        private String _TestProperty;
        public String TestProperty
        {
            get { return _TestProperty; }
            set { _TestProperty = value; }
        }
    }
And register it:
    FastReport.Utils.RegisteredObjects.Add(typeof(TestTextObject ), "ReportPage", new Bitmap(16,16), "TestTextObject", 0, false);
In a FastReport, I add a instance of TestTextObject and set ClickEvent, BeforePrintEvent, AfterPrintEvent
    DataBand _DataBand = FReport.FindObject("Data1") as DataBand;
    TestTextObject text3 = new TestTextObject ();
    text3.Bounds = new RectangleF(10, 10,
    Units.Centimeters * 10, Units.Centimeters * 0.5f);
    text3.Text = "中文字ddddddddd";
    text3.BeforePrintEvent = "text3_BeforePrint";
    text3.AfterPrintEvent = "text3_AfterPrint";
    text3.ClickEvent = "text3_Click";
    _DataBand.Objects.Add(text3);
The script like this:
    private void text3_BeforePrint(object sender, EventArgs e)
    {
      TestTextObject _PrintObject = sender as TestTextObject;
                  String[] _Expressions = (_PrintObject.OriginalComponent as FastReport.TextObject).GetExpressions();
                  foreach (String _Expression in _Expressions)
                  {
                      String[] _ElementList = _Expression.Split('.');
                      //it isn't from DataSource
               if (_ElementList.Length <= 1)
                          continue;
                      //TableName
               String TableName = _ElementList[_ElementList.Length - 2];
                      FastReport.Data.TableDataSource _DataSourceBase = _PrintObject.Report.Dictionary.FindByAlias(TableName) as FastReport.Data.TableDataSource;
                      if (_DataSourceBase == null)
                          _DataSourceBase = _PrintObject.Report.Dictionary.FindByName(TableName) as FastReport.Data.TableDataSource;
                       if (_DataSourceBase == null)
                            continue;
                      //Set the first value of DataRow   
                       _PrintObject.TestProperty = (_DataSourceBase.CurrentRow as System.Data.DataRow)[0].ToString();
                    }
    }
    private void text3_AfterPrint(object sender, EventArgs e)
    {
                     //the code is same to text3_BeforePrint
    }
    private void text3_Click(object sender, EventArgs e)
    {
      TestTextObject _PrintObject = sender as TestTextObject;  
      MessageBox.Show(_PrintObject.TestProperty.ToString());
    }
I expect the result of Message is: the first column's value of each datarow, But it is null! Why?! How can i do?
If use (PrintObject.OriginalComponent as TestTextObject).TestProperty, it get the value of last datarow

Comments

  • edited 3:40PM
    Hello,

    It's not so simple to create own report object. At least, you have to override the following methods of the new object:
        public override void Assign(Base source)
        {
          base.Assign(source);
          
          TestTextObject src = source as TestTextObject;
          TestProperty = src.TestProperty;
        }
    
        public override void Serialize(FRWriter writer)
        {
          TestTextObject c = writer.DiffObject as TestTextObject;
          base.Serialize(writer);
          
          if (TestProperty != c.TestProperty)
            writer.WriteStr("TestProperty", TestProperty);
        }
    
  • edited 3:40PM
    Thanks, it do work now!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.