Object Data Binding
Hello all. I am having a problem. I am a student in college, working part time in the lab for a co-op. A student came in with a problem that I could not help her fix. The application has 2 textboxes for user input (width and height), and 2 read-only text boxes to display the area and perimeter of the shape. Also, there is a dropdownlist that has the items 'circle', 'square' and 'rectangle' in it. I need to use a databinding control to bind the text boxes so that when the focus leaves the 2 text boxes with user-defined values, the read only textboxes display the correct result for the shape that is selected in the dropdownlist control, without having to click any calculate button. Can anyone help me out with this? Thanks.

Rajendra DeopuraPosted Oct 23, 2008, 1:43 AM
I have created a window application while taking your problem
Steps
1. Design a window application with a combobox named combobox1 and four textboxes named TextBox1,TextBox2,TextBox3and TextBox4. TextBox3 and TextBox4 are read only.
2. Fill the combobox with two option Circle,Rectangle. To fill the values, go to the smart tag of combobox and click edit items.
3. In the constructor of the form , after the InitialzeComponent Call write the follwing line :
Combobox1.SelectedIndex=0
4. Select the TextBox2_LostFocus( ) Event from the event list in view code, add the following code :
Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.LostFocus
Dim val1 As Integer = Integer.Parse(TextBox1.Text)
Dim val2 As Integer = Integer.Parse(TextBox2.Text)
Select Case ComboBox1.SelectedIndex
Case 0
Dim areaofcircle As Integer = 3.14F * val1 * val2
Dim circumference As Integer = 2 * val1 * val2
TextBox3.Text = areaofcircle.ToString
TextBox4.Text = circumference.ToString
Case 1
Dim area As Integer = val1 * val2
Dim peri = 2 * (val1 * val2)
TextBox3.Text = area.ToString
TextBox4.Text = peri.ToString
End Select
End Sub
I hope this will rectify your problem If you still need the project, drop me a mail at : [email protected]
Happy Coding !