Reports for WinForms | ComponentOne
Working with C1Report / Modifying the Fields / Prompting Users for Parameters
In This Topic
    Prompting Users for Parameters
    In This Topic

    Instead of highlighting products which are below the reorder level stored in the database, you could have the report prompt the user for the reorder level to use.

    To get the value from the user, you would change the report's RecordSource property to use a parameter query. (For details on how to build parameter queries, see Parameter Queries.)

    To write code in Visual Basic

    Visual Basic
    Copy Code
    c1r.DataSource.RecordSource = _        
      "PARAMETERS [Critical Stock Level] Short 10;" & _        
      c1r.DataSource.RecordSource
    

    To write code in C#

    C#
    Copy Code
    c1r.DataSource.RecordSource =          
    "PARAMETERS [Critical Stock Level] short 10;" +          
    c1r.DataSource.RecordSource;
    

    This setting causes the control to prompt the user for a "Critical Stock Level" value, which gets stored in a global VBScript variable where your events can use it. The default value for the variable is specified as 10.

    To use the value specified by the user, the script should be changed as follows:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim script As String = _        
      "level = [Critical Stock Level]" & vbCrLf & _        
      "If UnitsInStock < level Then" & vbCrLf & _        
      "  ProductNameCtl.ForeColor = RGB(255,0,0)" & vbCrLf & _       
      "  ProductNameCtl.Font.Bold = True" & vbCrLf & _       
      "Else" & vbCrLf & _        
      "  ProductNameCtl.ForeColor = RGB(0,0,0)" & vbCrLf & _        
      "  ProductNameCtl.Font.Bold = False" & vbCrLf & _        
      "End If"        
    c1r.Sections("Detail").OnPrint = script
    

    To write code in C#

    C#
    Copy Code
    string  script =          
      "level = [Critical Stock Level]\r\n" +          
      "if (UnitsInStock < level) then\r\n" +          
      "ProductNameCtl.ForeColor = rgb(255,0,0)\r\n" +          
      "ProductNameCtl.Font.Bold = true\r\n" +         
      "else\r\n" +          
      "ProductNameCtl.ForeColor = rgb(0,0,0)\r\n" +        
      "ProductNameCtl.Font.Bold = false\r\n" +          
      "end if\r\n";        
    c1r.Sections.Detail.OnPrint = script;
    

    The change is in the first two lines of the script. Instead of comparing the current value of the "UnitsInStock" filed to the reorder level stored in the database, the script compares it to the value entered by the user and stored in the "[Critical Stock Level]" VBScript variable.