TreeNodeBinding.FormatString プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TreeNodeBinding.FormatString プロパティの意味・解説 

TreeNodeBinding.FormatString プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

TreeNodeBinding オブジェクトが適用されるノードのテキストの表示形式を指定する文字列を取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<LocalizableAttribute(True)> _
Public Property FormatString As
 String
Dim instance As TreeNodeBinding
Dim value As String

value = instance.FormatString

instance.FormatString = value
[LocalizableAttribute(true)] 
public string FormatString { get;
 set; }
[LocalizableAttribute(true)] 
public:
property String^ FormatString {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_FormatString ()

/** @property */
public void set_FormatString (String value)
public function get FormatString
 () : String

public function set FormatString
 (value : String)

プロパティ値
TreeNodeBinding オブジェクトが適用されるノードのテキストの表示形式を指定する書式指定文字列。既定値は空の文字列 ("") です。FormatString プロパティが設定されていないことを示します。

解説解説

FormatString プロパティを使用して、ノードのテキストのカスタム書式を提供します。データ書式指定文字列は、{ A : Bxx } の書式で、コロンで区切られた 2 つの部分から構成されます。たとえば、書式指定文字列 {0:F2} を使用すると、2 桁の固定小数点数で表示されます。

メモメモ

文字列の全体はリテラル文字列ではなく、書式指定文字列であることを示すために、中かっこ ({}) で囲む必要があります。かっこの外側のテキストはリテラル テキストとして表示されます。

コロンの前の値 (一般的な例での A) は 0 から始まるパラメータのリストのパラメータ インデックスを指定します。

メモメモ

各ノードには 1 つの値しかないため、この値は必ず 0 に設定します。

コロンの後の文字 (一般的な例での B) は値の表示形式を指定します。共通の書式を次の表に示します。

書式指定文字の後の値 (一般的な例での xx) は、表示する有効桁数または小数点を指定します。

書式指定文字列の詳細については、「書式設定の概要」を参照してください。

このプロパティの値はビューステートに格納されます。

FormatString プロパティを設定している場合、デザイナ ツールを使用して、その値を自動的にリソース ファイルに保存できます。詳細については、LocalizableAttribute のトピックおよび「ASP.NET のグローバリゼーションおよびローカリゼーション」を参照してください。

使用例使用例

このセクションには、2 つのコード例が含まれています。FormatString プロパティを使用して、ルート ノードに表示されるテキストのカスタムの表示形式を指定する方法を最初のコード例に示します。最初のコード例に対応したサンプル XML データを 2 番目のコード例に示します。

FormatString プロパティを使用して、ルート ノードに表示されるテキストのカスタムの表示形式を指定する方法を次のコード例に示します。この例を正常に動作させるには、このコード例の後に示すサンプル XML データを、Book.xml という名前のファイルにコピーする必要があります。

<%@ Page Language="VB" %>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeNodeBinding FormatString Example</h3>
    
      <!-- Use the FormatString property to
 apply   -->
      <!-- a custom format string to the
 root node. -->
      <!-- The placeholder ({0}) is automatically   -->
      <!-- replaced with the value of the
 field     -->
      <!-- specified in the TextField property.
     --> 
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book"
 
            Depth="0"
            TextField="Title" 
            FormatString="Best Seller: {0}"/>
          <asp:TreeNodeBinding DataMember="Chapter"
 
            Depth="1" 
            TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Appendix"
 
            Depth="1" 
            TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"
  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

<%@ Page Language="C#" %>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeNodeBinding FormatString Example</h3>
    
      <!-- Use the FormatString property to apply   -->
      <!-- a custom format string to the root node. -->
      <!-- The placeholder ({0}) is automatically   -->
      <!-- replaced with the value of the field     -->
      <!-- specified in the TextField property.     -->
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            Depth="0"
            TextField="Title" 
            FormatString="Best Seller: {0}"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            Depth="1" 
            TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Appendix" 
            Depth="1" 
            TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

前の例に対応したサンプル XML データを次のコード例に示します。

<Book Title="Book Title">
    <Chapter Heading="Chapter 1">
        <Section Heading="Section 1">
        </Section>
        <Section Heading="Section 2">
        </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
        </Section>
    </Chapter>
    <Appendix Heading="Appendix A">
    </Appendix>
</Book>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNodeBinding クラス
TreeNodeBinding メンバ
System.Web.UI.WebControls 名前空間
TreeView
TreeNode クラス
DataBindings
その他の技術情報
書式設定の概要



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

TreeNodeBinding.FormatString プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeNodeBinding.FormatString プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS