Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So after a long while, I finally figured out how to solve the problem.</p> <p>Actually, I have done the coding in VB.net since I am more familiar with the VB syntax instead of C#'s. Nonetheless, the logic is pretty similar to each other since they are bounded by the .NET framework.</p> <p>The form property goes as follows (though enumerations in the original post is also possible.):</p> <pre><code>Public Property propGender() As String Get If RadioButton1.Checked = True Then Return "M" Else Return "F" End If End Get Set(ByVal value As String) _Sex = value If _Sex = "M" Then RadioButton1.Checked = True Else RadioButton2.Checked = True End If End Set End Property </code></pre> <p>That is trivial, but I only included that code snippet for further clarifications.</p> <p>The answer on how to data-bind a form property is simply:</p> <pre><code>Dim genderBinder = New Binding("propGender", Tbl_Stud_InfoBindingSource, "Gender") Me.DataBindings.Add(genderBinder) Me.DataBindings.Add(genderBinder) </code></pre> <p>where <code>Gender</code> is the data member I need. Adjusting the form properties with the use of the radio buttons is where I get confused(even until now, honestly). This problem was solved by implementing the <code>INotifyPropertyChanged</code> interface. I previously thought that this is implicitly included in every project, but easily found out that <code>System.ComponentModel</code> should be imported first. Thanks to <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged.aspx" rel="nofollow noreferrer">MSDN</a>.</p> <pre><code>Imports System.ComponentModel </code></pre> <p>Raising the protertyChanged event can be accomplished by:</p> <pre><code>Protected Sub OnPropertyChanged(ByVal name As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name)) End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged OnPropertyChanged("propGender") End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged OnPropertyChanged("propGender") End Sub </code></pre> <p>where RadioButton1 = radiobox for male and RadioButton2 = female (better to follow good naming conventions instead!).</p> <p>I am not that familiar with C# syntax but think that the equivalent code for raising checkChanged property is:</p> <pre><code>RadioButton1.CheckedChanged += (s, args) =&gt; OnPropertyChanged("propGender"); RadioButton2.CheckedChanged += (s, args) =&gt; OnPropertyChanged("propGender"); </code></pre> <p>Finally, in this way, I can now easily manage to bind radio buttons - I know it can be easy to solve this but a common question by beginners like me. In VB6, this can be implemented easily with the use of the popular recordsets. In .NET, the solution is not apparent.</p> <p><img src="https://i.stack.imgur.com/Ss8Cs.png" alt="enter image description here"></p> <p><strong>Edit:</strong> I saw some other questions pertaining to the same scenario here in SO. I found two, but they are both using C#, which may be fuzzy for VB users.</p> <p><strong>Edit:</strong> The missing key terminology I used to figure out is simply "Data binding radio button". That's why I want to change the title of this question to make it more definitive.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload