Search code examples
vb.netdynamiccrystal-reportspositionwidth

Change the Column width and Position programmatically in Crystal Reports


I want to create a report that has dynamic fields (columns). in the simpler words, there are 15 optional fields for user and the user will select 6 of them to be displayed in report.

so, for solution, I added all the columns in the report. and now I want to hide all non-selected columns and also change the width and position of the visible columns.

how can I do that in vb.net 2010 by coding?


Solution

  • As far as the width is concerned, you could use something like this, which will change the height and width (0 of course will hide it, so change it to a value that suits you).

    Dim RptDoc As New ReportDocument
     Dim _fldName As FieldObject
     _fldName = RptDoc.ReportDefinition.ReportObjects("fieldObjectName")
    _fldName.Width = 0
    _fldName.Height = 0
    

    About moving an object, you could try something like this:

    myReport _myReport = new myReport ();
    myReport .Section1.ReportObjects["myline"].Top = 10;
    

    You need to be aware of the Section naming in your report and the correct line reference.