ListObject.TotalsRowRange Property
Gets a Range that represents the Total row of the ListObject control.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
Syntax
'Declaration
ReadOnly Property TotalsRowRange As Range
Range TotalsRowRange { get; }
Property Value
Type: Range
A Range that represents the Total row of the ListObject control.
Remarks
This property returns a Range only if the Total row is showing in the ListObject control. If the Total row is not showing, it returns nulla null reference (Nothing in Visual Basic).
Examples
The following code example creates a DataTable and a ListObject, and binds the ListObject to the DataTable. It then gets the range that contains the Total row and changes the Total row font to italic.
This example is for a document-level customization.
Private Sub ListObject_TotalsRowRange()
' Create a new DataSet and DataTable.
Dim ds As New DataSet()
Dim dt As DataTable = ds.Tables.Add("Sales")
dt.Columns.Add(New DataColumn("Name"))
dt.Columns.Add(New DataColumn("Quarter1"))
' Add a new row to the DataTable.
Dim dr1 As DataRow = dt.NewRow()
dr1("Name") = "Sidney"
dr1("Quarter1") = "150"
dt.Rows.Add(dr1)
Dim dr2 As DataRow = dt.NewRow()
dr2("Name") = "Julia"
dr2("Quarter1") = "175"
dt.Rows.Add(dr2)
' Create a list object.
Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
Me.Controls.AddListObject(Me.Range("A1"), "List1")
' Bind the list object to the DataTable.
List1.AutoSetDataBoundColumnHeaders = True
List1.SetDataBinding(ds, "Sales", "Name", "Quarter1")
List1.ShowTotals = True
' Get the header row range and set the font to bold.
Dim totalRow As Excel.Range = List1.TotalsRowRange
totalRow.Cells.Font.Italic = True
End Sub
private void ListObject_TotalsRowRange()
{
// Create a new DataSet and DataTable.
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Sales");
dt.Columns.Add(new DataColumn("Name"));
dt.Columns.Add(new DataColumn("Quarter1"));
// Add a new row to the DataTable.
DataRow dr1 = dt.NewRow();
dr1["Name"] = "Sidney";
dr1["Quarter1"] = "150";
dt.Rows.Add(dr1);
DataRow dr2 = dt.NewRow();
dr2["Name"] = "Julia";
dr2["Quarter1"] = "175";
dt.Rows.Add(dr2);
// Create a list object.
Microsoft.Office.Tools.Excel.ListObject list1 =
this.Controls.AddListObject(
this.Range["A1"], "list1");
// Bind the list object to the DataTable.
list1.AutoSetDataBoundColumnHeaders = true;
list1.SetDataBinding(ds, "Sales", "Name",
"Quarter1");
list1.ShowTotals = true;
// Get the header row range and set the font to bold.
Excel.Range totalRow = list1.TotalsRowRange;
totalRow.Cells.Font.Italic = true;
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.