WinForm binding radio button

前端 未结 3 1862
别那么骄傲
别那么骄傲 2021-02-05 08:42

I use VS2010 and then drag and drop Member datagridview to design view. After that I drag and drop name member textfield to design view and then try to edit and save. It\'s work

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 09:23

    When making forms you can drag items from the "Data Sources" panel. In the data sources panel you can a class or table and all the children of it can be dragged to the form and will automatically generate a textbox or in this scenario a radio button with a data binding. In the database or class you will have to make a bit / bool for every option.

    Group the radio buttons and add a radio button without a databinding to keep all bit / bools 0.

    Set CausesValidation to False for all radio buttons.

    When saving the changes loop through all radio buttons like:

    ((YourClass)myBindingSource.DataSource).property1 = radioButton1.Checked;
    ((YourClass)myBindingSource.DataSource).property2 = radioButton2.Checked;
    

    I think this is a copy of How do I use databinding with Windows Forms radio buttons? And therefore, here is a copy of my answer there.

提交回复
热议问题