Binding a Group of Radio Buttons in a Windows Form

[ Team LiB ] Recipe Binding a Group of Radio Buttons in a Windows Form Problem You need to bind a field in a database to a radio button and update the database with the radio button selected. | Team LiB Recipe Binding a Group of Radio Buttons in a Windows Form Problem You need to bind a field in a database to a radio button and update the database with the radio button selected. Solution Use a hidden TextBox to retrieve and update the field value that corresponds to the radio button group. You can use the Tag property of each RadioButton control to hold its corresponding data field value. The schema of table TBL0709 used in this solution is shown in Table 7-9. Table 7-9. TBL0709 schema Column name Data type Length Allow nulls Id int 4 No RadioButtonItemId int 4 No Fieldl nvarchar 50 Yes The sample code contains seven event handlers Sets up the sample by creating a DataAdapter with the logic to select all records from table TBL0709 in the sample database and to update changes made back to the database. The DataAdapter is used to fill a DataTable in a new DataSet with the schema and data from TBL0709. The text boxes displaying the data for the fields in the record are bound to the three columns in the table Id RadioButtonItemId and Fieldl. The RadioButtonItemId TextBox is hidden. The BindingManagerBase is obtained for the TBL0709 table in the DataSet a handler is attached to manage the PositionChanged event and that handler is called to position the display on the first record. Update Iterates over the group of radio buttons to identify the one selected. The Tag property for the selected radio button is transferred to the hidden bound TextBox for update back to the database. Selects the radio button corresponding to the data field. The code iterates over the group of radio buttons. When the Tag property of a radio button matches the value in the TextBox that is bound to the data field the radio button is selected. Move First Sets the current record of the bound controls to the first record by setting the Position property of the BindingManagerBase object to 0. Move Previous .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.