次の方法で共有


DataGridTextBoxColumn.Format プロパティ

テキストの書式指定方法を指定する 1 文字以上の文字を取得または設定します。

Public Property Format As String
[C#]
public string Format {get; set;}
[C++]
public: __property String* get_Format();public: __property void set_Format(String*);
[JScript]
public function get Format() : String;public function set Format(String);

プロパティ値

テキストの書式指定方法を指定する 1 文字以上の文字。

解説

Format プロパティは、列に値を表示するときに適用する書式を指定します。たとえば、値の書式を地域通貨として指定する場合は、このプロパティを "c" に設定します。実際の通貨書式を確認するために、コンピュータの CultureInfo が使用されます。この値は、データが変更されると自動的に書式が解除され、ネイティブ型になります。

書式指定文字の詳細については、「 日付と時刻の書式指定文字列 」と「 標準の数値書式指定文字列 」を参照してください。

適用する書式は、データ型に適したものにする必要があります。たとえば、データが数値の場合は、数値の書式指定文字列を使用します。

DataGridTextBoxColumnCultureInfo を変更するには、 FormatInfo プロパティに、適切なカルチャ ID を指定して生成した新しい CultureInfo インスタンスを設定します。

アプリケーションの CultureInfo を設定するには、 Application オブジェクトの CurrentCulture プロパティに、適切なカルチャ ID を指定して生成した新しい CultureInfo インスタンスを設定します。

使用例

新しい CultureInfo オブジェクトを作成し、そのオブジェクトを DataGridTextBoxColumn オブジェクトの FormatInfo プロパティに割り当てる例を次に示します。この例では、列の値を通貨として表示することを指定するために、 Format プロパティを "c" に設定しています。

 
Public Class Form1:Inherits Form
private myDataGrid as DataGrid    
    Public Shared Sub Main()
        Dim t As New Form1()
        ' Write a purchase order.
    End Sub
Private Sub ChangeColumnCultureInfo()
   ' Create a new CultureInfo object using the 
   ' the locale ID for Italy. 
   Dim ItalyCultureInfo As CultureInfo = New _
   CultureInfo(&H0410)
   ' Cast a column that holds numeric values to the   
   ' DataGridTextBoxColumn type, and set the FormatInfo
   ' property to the new CultureInfo object. 
   Dim myGridTextBoxColumn As DataGridTextBoxColumn = _
   CType( myDataGrid.TableStyles("Orders"). _
   GridColumnStyles("OrderAmount"), DataGridTextBoxColumn)
   myGridTextBoxColumn.FormatInfo = ItalyCultureInfo
   myGridTextBoxColumn.Format = "c"
End Sub

[C#] 
private void ChangeColumnCultureInfo(){
   /* Create a new CultureInfo object using the 
   the locale ID for Italy. */
   System.Globalization.CultureInfo ItalyCultureInfo= 
   new CultureInfo(0x0410);
     
   /* Cast a column that holds numeric values to the   
   DataGridTextBoxColumn type, and set the FormatInfo
   property to the new CultureInfo object. */
   DataGridTextBoxColumn myGridTextBoxColumn = 
   (DataGridTextBoxColumn) myDataGrid.TableStyles["Orders"].
   GridColumnStyles["OrderAmount"];
   myGridTextBoxColumn.FormatInfo = ItalyCultureInfo;
   myGridTextBoxColumn.Format = "c";
}

[C++] 
private:
    void ChangeColumnCultureInfo() {
        /* Create a new CultureInfo Object* using the
        the locale ID for Italy. */
        System::Globalization::CultureInfo* ItalyCultureInfo =
            new CultureInfo(0x0410);

        /* Cast a column that holds numeric values to the
        DataGridTextBoxColumn type, and set the FormatInfo
        property to the new CultureInfo Object*. */
        DataGridTextBoxColumn* myGridTextBoxColumn =
            dynamic_cast<DataGridTextBoxColumn*>(
            myDataGrid->TableStyles->Item[S"Orders"]->
            GridColumnStyles->Item[S"OrderAmount"]);
        myGridTextBoxColumn->FormatInfo = ItalyCultureInfo;
        myGridTextBoxColumn->Format = S"c";
    }

[JScript] 
private function ChangeColumnCultureInfo(){
   // Create a new CultureInfo object using the 
   // the locale ID for Italy. 
   var ItalyCultureInfo : System.Globalization.CultureInfo = new CultureInfo(0x0410);
     
   // Cast a column that holds numeric values to the   
   // DataGridTextBoxColumn type, and set the FormatInfo
   // property to the new CultureInfo object. 
   var myGridTextBoxColumn : DataGridTextBoxColumn = 
   DataGridTextBoxColumn(myDataGrid.TableStyles["Orders"].
   GridColumnStyles["OrderAmount"]);
   
   myGridTextBoxColumn.FormatInfo = ItalyCultureInfo;
   myGridTextBoxColumn.Format = "c";
}

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataGridTextBoxColumn クラス | DataGridTextBoxColumn メンバ | System.Windows.Forms 名前空間 | CultureInfo | FormatInfo