次の方法で共有


SiteMapNodeCollection コンストラクター

定義

SiteMapNodeCollection クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
SiteMapNodeCollection()

既定のインスタンスである SiteMapNodeCollection クラスの新しいインスタンスを初期化します。

SiteMapNodeCollection(Int32)

指定した初期容量を使用して、 SiteMapNodeCollection クラスの新しいインスタンスを初期化します。

SiteMapNodeCollection(SiteMapNode)

SiteMapNodeCollection クラスの新しいインスタンスを初期化し、コレクションのInnerList プロパティにSiteMapNode オブジェクトを追加します。

SiteMapNodeCollection(SiteMapNode[])

SiteMapNodeCollection クラスの新しいインスタンスを初期化し、コレクションのInnerList プロパティにSiteMapNode型の配列を追加します。

SiteMapNodeCollection(SiteMapNodeCollection)

SiteMapNodeCollection クラスの新しいインスタンスを初期化し、指定したSiteMapNodeCollection コレクションのすべてのリスト アイテムをコレクションのInnerList プロパティに追加します。

SiteMapNodeCollection()

既定のインスタンスである SiteMapNodeCollection クラスの新しいインスタンスを初期化します。

public:
 SiteMapNodeCollection();
public SiteMapNodeCollection();
Public Sub New ()

次のコード例では、SiteMapNodeCollection コンストラクターを使用して新しいSiteMapNodeCollection コレクションを作成し、Add メソッドを使用してSiteMapNodeCollectionに要素を追加する方法を示します。

// The LoadSiteMapData() method loads site navigation
// data from persistent storage into a DataTable.
DataTable siteMap = LoadSiteMapData();

// Create a SiteMapNodeCollection.
SiteMapNodeCollection nodes = new SiteMapNodeCollection();

// Create a SiteMapNode and add it to the collection.
SiteMapNode tempNode;
DataRow row;
int index = 0;

while (index < siteMap.Rows.Count)
{

    row = siteMap.Rows[index];

    // Create a node based on the data in the DataRow.
    tempNode = new SiteMapNode(SiteMap.Provider,
                                row["Key"].ToString(),
                                row["Url"].ToString());

    // Add the node to the collection.
    nodes.Add(tempNode);
    ++index;
}
' The LoadSiteMapData() Function loads site navigation
' data from persistent storage into a DataTable.

Dim siteMapData As DataTable
siteMapData = LoadSiteMapData()

' Create a SiteMapNodeCollection.
Dim nodes As New SiteMapNodeCollection()

' Create a SiteMapNode and add it to the collection.
Dim tempNode As SiteMapNode
Dim row As DataRow
Dim index As Integer
index = 0

While (index < siteMapData.Rows.Count)

    row = siteMapData.Rows(index)

    ' Create a node based on the data in the DataRow.
    tempNode = New SiteMapNode(SiteMap.Provider, row("Key").ToString(), row("Url").ToString())

    ' Add the node to the collection.
    nodes.Add(tempNode)
    index = index + 1
End While

注釈

SiteMapNodeCollection コンストラクターを使用して、空のSiteMapNodeCollection コレクションを作成します。 AddAddRange、またはInsertメソッドを使用して、SiteMapNodeCollectionに要素を追加できます。

こちらもご覧ください

適用対象

SiteMapNodeCollection(Int32)

指定した初期容量を使用して、 SiteMapNodeCollection クラスの新しいインスタンスを初期化します。

public:
 SiteMapNodeCollection(int capacity);
public SiteMapNodeCollection(int capacity);
new System.Web.SiteMapNodeCollection : int -> System.Web.SiteMapNodeCollection
Public Sub New (capacity As Integer)

パラメーター

capacity
Int32

SiteMapNodeCollectionの初期容量。

注釈

SiteMapNodeCollection コンストラクターを使用して、指定した初期容量を持つSiteMapNodeCollection コレクションを作成します。

こちらもご覧ください

適用対象

SiteMapNodeCollection(SiteMapNode)

SiteMapNodeCollection クラスの新しいインスタンスを初期化し、コレクションのInnerList プロパティにSiteMapNode オブジェクトを追加します。

public:
 SiteMapNodeCollection(System::Web::SiteMapNode ^ value);
public SiteMapNodeCollection(System.Web.SiteMapNode value);
new System.Web.SiteMapNodeCollection : System.Web.SiteMapNode -> System.Web.SiteMapNodeCollection
Public Sub New (value As SiteMapNode)

パラメーター

例外

valuenullです。

次のコード例では、1 つの初期SiteMapNode オブジェクトを持つSiteMapNodeCollection コレクションを作成し、AddRange メソッドを使用してSiteMapNode オブジェクトのSiteMapNodeCollectionを追加する方法を示します。 個々のSiteMapNode オブジェクトが読み取り専用である場合でも、SiteMapNodeCollectionを変更できます。


// Create a SiteMapNodeCollection with all the nodes
// from the first two hierarchical levels of the current
// site map.
SiteMapNodeCollection baseCollection =
    new SiteMapNodeCollection(SiteMap.RootNode);

SiteMapNodeCollection childCollection =
    SiteMap.RootNode.ChildNodes;

baseCollection.AddRange(childCollection);

Response.Write( "<BR>Derived SiteMapNodeCollection.<BR><HR><BR>");
foreach (SiteMapNode node in baseCollection) {
    Response.Write( node.Title + "<BR>");
}

' Create a SiteMapNodeCollection with all the nodes
' from the first two hierarchical levels of the current
' site map.
Dim baseCollection As SiteMapNodeCollection
baseCollection = New SiteMapNodeCollection(SiteMap.RootNode)

Dim childCollection As SiteMapNodeCollection = SiteMap.RootNode.ChildNodes

baseCollection.AddRange(childCollection)

Response.Write( "<BR>Derived SiteMapNodeCollection.<BR><HR><BR>")

For Each node In baseCollection
    Response.Write( node.Title + "<BR>")
Next

注釈

SiteMapNodeCollection コンストラクターを使用して、1 つの初期SiteMapNode オブジェクトを持つSiteMapNodeCollection コレクションを作成します。 AddAddRange、またはInsertメソッドを使用して、SiteMapNodeCollectionに要素を追加できます。

こちらもご覧ください

適用対象

SiteMapNodeCollection(SiteMapNode[])

SiteMapNodeCollection クラスの新しいインスタンスを初期化し、コレクションのInnerList プロパティにSiteMapNode型の配列を追加します。

public:
 SiteMapNodeCollection(cli::array <System::Web::SiteMapNode ^> ^ value);
public SiteMapNodeCollection(System.Web.SiteMapNode[] value);
new System.Web.SiteMapNodeCollection : System.Web.SiteMapNode[] -> System.Web.SiteMapNodeCollection
Public Sub New (value As SiteMapNode())

パラメーター

value
SiteMapNode[]

SiteMapNodeCollectionに追加するSiteMapNode型の配列。

例外

valuenullです。

注釈

SiteMapNodeCollection コンストラクターの使用は、SiteMapNodeCollection コンストラクターを呼び出し、AddRange メソッドを使用してSiteMapNodeCollection コレクションに要素を追加することと同じです。

こちらもご覧ください

適用対象

SiteMapNodeCollection(SiteMapNodeCollection)

SiteMapNodeCollection クラスの新しいインスタンスを初期化し、指定したSiteMapNodeCollection コレクションのすべてのリスト アイテムをコレクションのInnerList プロパティに追加します。

public:
 SiteMapNodeCollection(System::Web::SiteMapNodeCollection ^ value);
public SiteMapNodeCollection(System.Web.SiteMapNodeCollection value);
new System.Web.SiteMapNodeCollection : System.Web.SiteMapNodeCollection -> System.Web.SiteMapNodeCollection
Public Sub New (value As SiteMapNodeCollection)

パラメーター

例外

valuenullです。

次のコード例では、SiteMapNode オブジェクトの別のSiteMapNodeCollectionをベースとして使用してSiteMapNodeCollection コレクションを作成する方法を示します。 SiteMapNode.GetAllNodes メソッドは読み取り専用のSiteMapNodeCollectionを返します。これは、IsReadOnly プロパティがtrueを返したときに検出されます。 読み取り専用SiteMapNodeCollectionを使用して新しいSiteMapNodeCollectionが作成され、AddメソッドとRemoveメソッドを正常に呼び出すことができます。

SiteMapNodeCollection siteNodes = SiteMap.RootNode.GetAllNodes();

if ( siteNodes.IsReadOnly ||
     siteNodes.IsFixedSize )
{
    Response.Write("Collection is read-only or has fixed size.<BR>");

    // Create a new, modifiable collection from the existing one.
    SiteMapNodeCollection modifiableCollection =
         new SiteMapNodeCollection(siteNodes);

    // The MoveNode example method moves a node from position one to
    // the last position in the collection.
    MoveNode(modifiableCollection);
}
else {
    MoveNode(siteNodes);
}

Dim siteNodes As SiteMapNodeCollection
siteNodes = SiteMap.RootNode.GetAllNodes()

If siteNodes.IsReadOnly Or siteNodes.IsFixedSize Then

    Response.Write("Collection is read-only or has fixed size.<BR>")

    ' Create a new, modifiable collection from the existing one.
    Dim modifiableCollection As SiteMapNodeCollection
    modifiableCollection = New SiteMapNodeCollection(siteNodes)

    ' The MoveNode example method moves a node from position one to
    ' the last position in the collection.
    MoveNode(modifiableCollection)
Else
    MoveNode(siteNodes)
End If

注釈

SiteMapNodeCollection コンストラクターの使用は、SiteMapNodeCollection コンストラクターを呼び出し、AddRange メソッドを使用してSiteMapNodeCollection コレクションに要素を追加することと同じです。

適用対象