Using Expression Columns to Display Calculated Values

[ Team LiB ] Recipe Using Expression Columns to Display Calculated Values Problem You need to display a calculated value for each row in a DataTable and to filter and sort the table on this value. Solution Add an expression column to the table and display it. | Team LiB Recipe Using Expression Columns to Display Calculated Values Problem You need to display a calculated value for each row in a DataTable and to filter and sort the table on this value. Solution Add an expression column to the table and display it. Sort and filter on the expression column from the default DataView for the table. The sample code contains two event handlers Sets up the sample by creating a DataTable containing the Order Details table from the Northwind sample database. An expression column calculating the extended price for each detail line is created and added to the table. Finally the default view for the table is bound to the data grid on the form. Apply Applies the filter and sort order entered by the user to the Extended Price expression column in the data view. The C code is shown in Example 3-2. Example 3-2. File Namespaces variables and constants using System using using using using . . . private void ExpressionColumnForm_Load object sender e Define the table and fill it with data. DataTable dt new DataTable OrderDetails String selectText SELECT FROM Order Details SqlDataAdapter da new SqlDataAdapter selectText S ql_ConnectString dt Add an expression column to the table. new DataColumn ExtendedPrice typeof Decimal Quantity UnitPrice 1 - Discount Define the DataView object. dv Bind the DataView to the DataGrid. dv private void applyButton_Click object sender e bool isLowerBound false bool isUpperBound false Decimal lowerBound 0 Decimal upperBound 0 if .Length 0 isLowerBound true try lowerBound catch Invalid entry for lower bound. Error .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
144    128    5    23-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.