Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Anda dapat menggunakan DataViewManager untuk mengelola pengaturan tampilan untuk semua tabel dalam DataView. Jika Anda memiliki kontrol yang ingin Anda ikat ke beberapa tabel, seperti kisi yang menavigasi hubungan, DataViewManager sangat ideal.
DataViewManager berisi kumpulan DataViewSetting objek yang digunakan untuk mengatur pengaturan tampilan tabel di DataSet.
DataViewSettingCollection berisi satu DataViewSetting objek untuk setiap tabel dalam Himpunan Data. Anda dapat mengatur properti default ApplyDefaultSort, Sort, RowFilter, dan RowStateFilter properti tabel yang dirujuk dengan menggunakan DataViewSetting-nya. Anda dapat mereferensikan DataViewSetting untuk tabel tertentu berdasarkan nama atau referensi ordinal, atau dengan meneruskan referensi ke objek tabel tertentu. Anda dapat mengakses kumpulan DataViewSetting objek dalam dengan DataViewManager menggunakan DataViewSettings properti .
Contoh kode berikut mengisi DataSet dengan tabel database SQL Server NorthwindPelanggan, Pesanan, dan Detail Pesanan, membuat hubungan antara tabel, menggunakan DataViewManager untuk mengatur pengaturan default DataView , dan mengikat DataGrid ke DataViewManager. Contoh mengatur pengaturan default DataView untuk semua tabel dalam DataSet untuk mengurutkan menurut kunci utama tabel (ApplyDefaultSort = true), lalu memodifikasi susunan Customers urutan tabel untuk diurutkan menurut CompanyName.
' Assumes connection is a valid SqlConnection to Northwind.
' Create a Connection, DataAdapters, and a DataSet.
Dim custDA As SqlDataAdapter = New SqlDataAdapter( _
"SELECT CustomerID, CompanyName FROM Customers", connection)
Dim orderDA As SqlDataAdapter = New SqlDataAdapter( _
"SELECT OrderID, CustomerID FROM Orders", connection)
Dim ordDetDA As SqlDataAdapter = New SqlDataAdapter( _
"SELECT OrderID, ProductID, Quantity FROM [Order Details]", connection)
Dim custDS As DataSet = New DataSet()
' Open the Connection.
connection.Open()
' Fill the DataSet with schema information and data.
custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
orderDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
ordDetDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
custDA.Fill(custDS, "Customers")
orderDA.Fill(custDS, "Orders")
ordDetDA.Fill(custDS, "OrderDetails")
' Close the Connection.
connection.Close()
' Create relationships.
custDS.Relations.Add("CustomerOrders", _
custDS.Tables("Customers").Columns("CustomerID"), _
custDS.Tables("Orders").Columns("CustomerID"))
custDS.Relations.Add("OrderDetails", _
custDS.Tables("Orders").Columns("OrderID"), _
custDS.Tables("OrderDetails").Columns("OrderID"))
' Create default DataView settings.
Dim viewManager As DataViewManager = New DataViewManager(custDS)
Dim viewSetting As DataViewSetting
For Each viewSetting In viewManager.DataViewSettings
viewSetting.ApplyDefaultSort = True
Next
viewManager.DataViewSettings("Customers").Sort = "CompanyName"
' Bind to a DataGrid.
Dim grid As System.Windows.Forms.DataGrid = New System.Windows.Forms.DataGrid()
grid.SetDataBinding(viewManager, "Customers")
// Assumes connection is a valid SqlConnection to Northwind.
// Create a Connection, DataAdapters, and a DataSet.
SqlDataAdapter custDA = new SqlDataAdapter(
"SELECT CustomerID, CompanyName FROM Customers", connection);
SqlDataAdapter orderDA = new SqlDataAdapter(
"SELECT OrderID, CustomerID FROM Orders", connection);
SqlDataAdapter ordDetDA = new SqlDataAdapter(
"SELECT OrderID, ProductID, Quantity FROM [Order Details]", connection);
DataSet custDS = new DataSet();
// Open the Connection.
connection.Open();
// Fill the DataSet with schema information and data.
custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
orderDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
ordDetDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
custDA.Fill(custDS, "Customers");
orderDA.Fill(custDS, "Orders");
ordDetDA.Fill(custDS, "OrderDetails");
// Close the Connection.
connection.Close();
// Create relationships.
custDS.Relations.Add("CustomerOrders",
custDS.Tables["Customers"].Columns["CustomerID"],
custDS.Tables["Orders"].Columns["CustomerID"]);
custDS.Relations.Add("OrderDetails",
custDS.Tables["Orders"].Columns["OrderID"],
custDS.Tables["OrderDetails"].Columns["OrderID"]);
// Create default DataView settings.
DataViewManager viewManager = new DataViewManager(custDS);
foreach (DataViewSetting viewSetting in viewManager.DataViewSettings)
viewSetting.ApplyDefaultSort = true;
viewManager.DataViewSettings["Customers"].Sort = "CompanyName";
// Bind to a DataGrid.
System.Windows.Forms.DataGrid grid = new System.Windows.Forms.DataGrid();
grid.SetDataBinding(viewManager, "Customers");