tailieunhanh - Using a DataView to Control Edits, Deletions, or Additions in Windows Forms
[ Team LiB ] Recipe Using a DataView to Control Edits, Deletions, or Additions in Windows Forms Problem You need to selectively prevent users from editing, deleting, or adding data in a Windows Forms application. Solution Bind a DataView to Windows Forms controls. The sample code contains four event handlers | Team LiB Recipe Using a DataView to Control Edits Deletions or Additions in Windows Forms Problem You need to selectively prevent users from editing deleting or adding data in a Windows Forms application. Solution Bind a DataView to Windows Forms controls. The sample code contains four event handlers Sets up the sample by filling a DataTable with the Orders table from the Northwind sample database. A DataView is created from the table and bound to the data grid on the form. Allow Delete Sets whether the DataView allows records to be deleted based on the value in a check box. Allow Edit Sets whether the DataView allows records to be edited based on the value in a check box. Allow Insert Sets whether the DataView allows records to be inserted based on the value in a check box. The C code is shown in Example 7-30. Example 7-30. File Namespaces variables and constants using System using using using private DataView dv . . . private void ControlDataEditWithDataViewForm_Load object sender e Fill the Order table. SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders S ql_ConnectString DataTable dtOrders new DataTable Orders dtOrders dtOrders Create a view and bind it to the grid. dv new DataView dtOrders dv private void allowDeleteCheckBox_CheckedChanged object sender e private void allowEditCheckBox_CheckedChanged object sender e private void allowInsertCheckBox_CheckedChanged object sender e Discussion The DataGrid control does not have properties that control the adding editing or deleting the data in the control. Binding a DataGrid to a .
đang nạp các trang xem trước