# GrapeCity.ActiveReports.SectionReport.AddNamedItem

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="GrapeCity_ActiveReports_SectionReport_AddNamedItem_" data-uid="GrapeCity.ActiveReports.SectionReport.AddNamedItem*">AddNamedItem Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="GrapeCity_ActiveReports_SectionReport_AddNamedItem_" data-uid="GrapeCity.ActiveReports.SectionReport.AddNamedItem*"></a>
<h4 id="GrapeCity_ActiveReports_SectionReport_AddNamedItem_System_String_System_Object_" data-uid="GrapeCity.ActiveReports.SectionReport.AddNamedItem(System.String,System.Object)">AddNamedItem(string, object)</h4>
<div class="markdown level1 summary"><p>Adds the object to the global namespace of the script.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void AddNamedItem(string objectName, object objectReference)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">objectName</span></td>
      <td><p>A <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a> value representing the name of the object to be used in the script.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></td>
      <td><span class="parametername">objectReference</span></td>
      <td><p>An <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a> value that references the object to be used in the script.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="GrapeCity_ActiveReports_SectionReport_AddNamedItem_System_String_System_Object__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method allows scripts to become aware of custom classes contained within a project.		
Once an item has been added, the script can use the objectName string to reference the object and the functions contained within the class.</p>
</div>
<h5 id="GrapeCity_ActiveReports_SectionReport_AddNamedItem_System_String_System_Object__examples">Examples</h5>
<pre><code class="lang-csharp">var sectionReport = new GrapeCity.ActiveReports.SectionReport();
sectionReport.Document.Printer.PrinterName = String.Empty;
sectionReport.CompatibilityMode = GrapeCity.ActiveReports.Document.CompatibilityModes.CrossPlatform;
var ctl = new GrapeCity.ActiveReports.SectionReportModel.TextBox{Name = "text1"};
sectionReport.Sections.Add(new GrapeCity.ActiveReports.SectionReportModel.Detail{Name = "Details"});
sectionReport.Sections[0].Controls.Add(ctl);
sectionReport.ScriptLanguage = "C#";
sectionReport.Script = @"public void Detail_Format(){text1.Text = text1Value;}";
this.AddNamedItem("text1Value", "Hello World!");</code></pre>

<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></td>
      <td><p>Thrown if the <code class="paramref">objectName</code> or <code class="paramref">objectReference</code> is null.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
