DataGrid.SetDataBinding メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGrid.SetDataBinding メソッドの意味・解説 

DataGrid.SetDataBinding メソッド

実行時に DataSource プロパティと DataMember プロパティを設定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Sub SetDataBinding ( _
    dataSource As Object, _
    dataMember As String _
)
Dim instance As DataGrid
Dim dataSource As Object
Dim dataMember As String

instance.SetDataBinding(dataSource, dataMember)
public void SetDataBinding (
    Object dataSource,
    string dataMember
)
public:
void SetDataBinding (
    Object^ dataSource, 
    String^ dataMember
)
public void SetDataBinding (
    Object dataSource, 
    String dataMember
)
public function SetDataBinding (
    dataSource : Object, 
    dataMember : String
)

パラメータ

dataSource

System.Windows.Forms.DataGrid コントロールのデータ ソース。

dataMember

DataSource プロパティによって返されたオブジェクト内で、バインド先のテーブルを指定する DataMember 文字列。

例外例外
例外の種類条件

ArgumentException

1 つ以上の引数が無効です。

ArgumentNullException

dataSource 引数が null 参照 (Visual Basic では Nothing) です。

解説解説

実行時に SetDataBinding メソッドを使用して、DataSource プロパティをリセットする必要があります。

有効なデータ ソースを設定する方法の詳細については、DataSource プロパティのトピックを参照してください。

作成したグリッドで、ユーザーはデータを編集できるが、新しい行を追加できないようにするには、DataView をデータ ソースとして使用し、AllowNew プロパティを false に設定します。DataSource が DataView または DataTable の場合は、DataMember を空の文字列 ("") に設定します。

使用例使用例

DataSource を DataSet に設定し、DataMember を、その DataSet 内の DataTable に設定するコード例を次に示します。

Private Sub BindControls()
    ' Create a DataSet named SuppliersProducts.
    Dim SuppliersProducts As New
 DataSet("SuppliersProducts")
    ' Adds two DataTable objects, Suppliers and Products.
    SuppliersProducts.Tables.Add(New DataTable("Suppliers"))
    SuppliersProducts.Tables.Add(New DataTable("Products"))
    ' Insert code to add DataColumn objects.
    ' Insert code to fill tables with columns and data.
    ' Binds the DataGrid to the DataSet, displaying the Suppliers table.
    dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers")
End Sub 'BindControls
private void BindControls(){
    // Creates a DataSet named SuppliersProducts.
    DataSet SuppliersProducts = new DataSet("SuppliersProducts");
    // Adds two DataTable objects, Suppliers and Products.
    SuppliersProducts.Tables.Add(new DataTable("Suppliers"));
    SuppliersProducts.Tables.Add(new DataTable("Products"));
    // Insert code to add DataColumn objects.
    // Insert code to fill tables with columns and data.
    // Binds the DataGrid to the DataSet, displaying the Suppliers table.
    dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers");
 }
   
private:
   void BindControls()
   {
      // Creates a DataSet named SuppliersProducts.
      DataSet^ SuppliersProducts = gcnew DataSet( "SuppliersProducts" );
      // Adds two DataTable objects, Suppliers and Products.
      SuppliersProducts->Tables->Add( gcnew DataTable( "Suppliers"
 ) );
      SuppliersProducts->Tables->Add( gcnew DataTable( "Products"
 ) );
      // Insert code to add DataColumn objects.
      // Insert code to fill tables with columns and data.
      // Binds the DataGrid to the DataSet, displaying the Suppliers
 table.
      dataGrid1->SetDataBinding( SuppliersProducts, "Suppliers" );
   }
private void BindControls()
{
    // Creates a DataSet named SuppliersProducts.
    DataSet suppliersProducts = new DataSet("SuppliersProducts");
    // Adds two DataTable objects, Suppliers and Products.
    suppliersProducts.get_Tables().Add(new DataTable("Suppliers"));
    suppliersProducts.get_Tables().Add(new DataTable("Products"));
    // Insert code to add DataColumn objects.
    // Insert code to fill tables with columns and data.
    // Binds the DataGrid to the DataSet, displaying the Suppliers table.
    dataGrid1.SetDataBinding(suppliersProducts, "Suppliers");
} //BindControls
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGrid クラス
DataGrid メンバ
System.Windows.Forms 名前空間
DataMember
DataSource
DataSet
DataView



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

DataGrid.SetDataBinding メソッドのお隣キーワード
検索ランキング

   

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



DataGrid.SetDataBinding メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS