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

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

DataGrid.DataSource プロパティ

グリッドデータ表示される対象データ ソース取得または設定します

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

Dim instance As DataGrid
Dim value As Object

value = instance.DataSource

instance.DataSource = value
public Object DataSource { get; set;
 }
/** @property */
public Object get_DataSource ()

/** @property */
public void set_DataSource (Object value)

プロパティ
データ ソースとして機能するオブジェクト

解説解説

実行時DataSource プロパティと DataMember プロパティ設定するには、SetDataBinding メソッド使用します

有効なデータ ソース次に示します

データ ソース詳細については、Binding クラス概要トピック参照してください

DataSource 参照複数テーブル格納している場合は、DataMember プロパティバインド先のテーブル指定する文字列設定する必要があります。たとえば、DataSourceDataSet または DataViewManager であり、CustomersOrders、および OrderDetails という名前の 3 つのテーブル格納している場合は、バインド先のテーブル指定する必要があります

IList インターフェイス実装ていないオブジェクト、または IListSourceDataSource設定すると、グリッドによって例外スローさます。

作成したグリッドで、ユーザーデータ編集できるが、新しい行を追加できないようにするには、DataViewデータ ソースとして使用し、AddNew プロパティfalse設定します

DataGrid をオブジェクト厳密に指定され配列バインドするには、オブジェクト型パブリック プロパティ含まれている必要があります配列表示する DataGridTableStyle を作成するには、DataGridTableStyle.MappingName プロパティtypename設定します。なお、この typename実際オブジェクト型名に置き換えてくださいまた、MappingName プロパティでは大文字と小文字区別されることに注意してください。型の名前は正確に指定する必要があります例については、MappingName プロパティトピック参照してください

また、DataGrid を ArrayList にバインドできますArrayList特長は、複数の型のオブジェクト格納できることです。ただし、DataGridリスト内のすべての項目の型が 1 番目の項目の型と同じ場合限りリストバインドできます。つまり、すべてのオブジェクトの型が同じであるか、リスト内の最初の項目と同じクラスからすべてのクラス継承している必要があります。たとえば、リスト内の最初の項目が Control場合2 番目の項目は (Control から継承した) TextBoxできます逆に、1 番目の項目が TextBox場合2 番目のオブジェクトControl になることはできません。さらに、ArrayList は、バインディングするときは、項目を含んでいる必要があります。空の ArrayList場合、空のグリッドとなります。さらに、ArrayListオブジェクトにはパブリック プロパティ含まれている必要がありますArrayListバインディングするときは、DataGridTableStyleMappingName を "ArrayList" (型の名前) に設定します

使用例使用例

DataSource と、必要に応じて DataMember設定してSystem.Windows.Forms.DataGridDataViewDataSet両方バインドする方法次のコード例示します。この例では、System.Windows.Forms.DataGrid からデータ ソース返す方法示します

Private Sub BindToDataView(myGrid As
 DataGrid)
    ' Create a DataView using the DataTable.
    Dim myTable As New DataTable("Suppliers")
    ' Insert code to create and populate columns.
    Dim myDatatView As New
 DataView(myTable)
    myGrid.DataSource = myDatatView
End Sub 'BindToDataView

Private Sub BindToDataSet(myGrid As
 DataGrid)
    ' Create a DataSet.
    Dim myDataSet As New
 DataSet("myDataSet")
    ' Insert code to populate DataSet with several tables.
    myGrid.DataSource = myDataSet
    ' Use the DataMember property to specify the DataTable.
    myGrid.DataMember = "Suppliers"
End Sub 'BindToDataSet

Private Function GetDataViewFromDataSource()
 As DataView
    ' Create a DataTable variable, and set it to the DataSource.
    Dim myDatatView As DataView
    myDatatView = CType(dataGrid1.DataSource, DataView)
    Return myDatatView
End Function 'GetDataViewFromDataSource

Private Function GetDataSetFromDataSource()
 As DataSet
    ' Create a DataSet variable, and set it to the DataSource.
    Dim myDataSet As DataSet
    myDataSet = CType(dataGrid1.DataSource, DataSet)
    Return myDataSet
End Function 'GetDataSetFromDataSource
private void BindToDataView(DataGrid myGrid){
    // Create a DataView using the DataTable.
    DataTable myTable = new DataTable("Suppliers");
    // Insert code to create and populate columns.
    DataView myDataView = new DataView(myTable);
    myGrid.DataSource = myDataView;
 }
 private void BindToDataSet(DataGrid myGrid){
    // Create a DataSet.
    DataSet myDataSet = new DataSet("myDataSet");
    // Insert code to populate DataSet with several tables.
    myGrid.DataSource = myDataSet;
    // Use the DataMember property to specify the DataTable.
    myGrid.DataMember = "Suppliers";
 }
 private DataView GetDataViewFromDataSource(){
    // Create a DataTable variable, and set it to the DataSource.
    DataView myDataView;
    myDataView = (DataView) dataGrid1.DataSource;
    return myDataView;
 }
 private DataSet GetDataSetFromDataSource(){
    // Create a DataSet variable, and set it to the DataSource.
    DataSet myDataSet;
    myDataSet = (DataSet) dataGrid1.DataSource;
    return myDataSet;
 }

private:
   void BindToDataView( DataGrid^ myGrid )
   {
      // Create a DataView using the DataTable.
      DataTable^ myTable = gcnew DataTable( "Suppliers" );
      // Insert code to create and populate columns.
      DataView^ myDataView = gcnew DataView( myTable );
      myGrid->DataSource = myDataView;
   }

   void BindToDataSet( DataGrid^ myGrid )
   {
      // Create a DataSet.
      DataSet^ myDataSet = gcnew DataSet( "myDataSet" );
      // Insert code to populate DataSet with several tables.
      myGrid->DataSource = myDataSet;
      // Use the DataMember property to specify the DataTable.
      myGrid->DataMember = "Suppliers";
   }

   DataView^ GetDataViewFromDataSource()
   {
      // Create a DataTable variable, and set it to the DataSource.
      DataView^ myDataView;
      myDataView = (DataView^)(dataGrid1->DataSource);
      return myDataView;
   }

   DataSet^ GetDataSetFromDataSource()
   {
      // Create a DataSet variable, and set it to the DataSource.
      DataSet^ myDataSet;
      myDataSet = (DataSet^)(dataGrid1->DataSource);
      return myDataSet;
   }
private void BindToDataView(DataGrid myGrid)
{
    // Create a DataView using the DataTable.
    DataTable myTable = new DataTable("Suppliers");
    // Insert code to create and populate columns.
    DataView myDataView = new DataView(myTable);
    myGrid.set_DataSource(myDataView);
} //BindToDataView

private void BindToDataSet(DataGrid myGrid)
{
    // Create a DataSet.
    DataSet myDataSet = new DataSet("myDataSet");
    // Insert code to populate DataSet with several tables.
    myGrid.set_DataSource(myDataSet);
    // Use the DataMember property to specify the DataTable.
    myGrid.set_DataMember("Suppliers");
} //BindToDataSet

private DataView GetDataViewFromDataSource()
{
    // Create a DataTable variable, and set it to the DataSource.
    DataView myDataView;
    myDataView = (DataView)(dataGrid1.get_DataSource());
    return myDataView;
} //GetDataViewFromDataSource

private DataSet GetDataSetFromDataSource()
{
    // Create a DataSet variable, and set it to the DataSource.
    DataSet myDataSet;
    myDataSet = ((DataSet)(dataGrid1.get_DataSource()));
    return myDataSet;
} //GetDataSetFromDataSource
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGrid クラス
DataGrid メンバ
System.Windows.Forms 名前空間
DataGrid.DataMember プロパティ
DataSet
DataViewManager
DataView


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataGrid.DataSource プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataGrid.DataSource プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataGrid.DataSource プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGrid.DataSource プロパティ」の関連用語

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

   

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



DataGrid.DataSource プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS