Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a number of databound textboxs, a textbox variable, a measure button, and a save button on a form.

the textbox variable allows auto incrementing of the textboxes after the measure button is pushed and a value is read. I use a doubleclick function on the textboxes also to allow the user to implement a measure function.

relevant code:

VB
Private Sub btn_Measure_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_HA_Measure.Click
        If Not IsNothing(measure_current_textbox) Then
            test_measurement(measure_current_textbox)
        Else
            MessageBox.Show("No angle has been selected, please select an textbox to measure", "Error", MessageBoxButtons.OK)
        End If
    End Sub


VB
Private Sub tbx_Angle_SingleClick(sender As System.Object, e As System.EventArgs) Handles tbx_HA_F1T1.Click, tbx_HA_F1T2.Click
     measure_current_textbox = TryCast(sender, TextBox)
 End Sub


VB
Private Sub tbx_Angle_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbx_HA_F1T1.DoubleClick, tbx_HA_F1T2.DoubleClick
       If Not IsNothing(measure_current_textbox) Then
           test_measurement(measure_current_textbox)
       Else
           MessageBox.Show("No angle has been selected, please select an textbox to measure", "Error", MessageBoxButtons.OK)
       End If
   End Sub


VB
Private Sub test_measurement(ByVal sender As Textbox)
       measure_current_textbox.Text = FormatNumber(5.0, 4)
  End Sub


VB
Private Sub btn_Accept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Accept.Click
        Try
            TSLinqSQLDataContext.SubmitChanges()
            Me.Close()
        Catch ex As Exception
            MessageBox.Show(Me, ex.Message, "Database Write Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub


So both functions call the test_measurement function, both pass the same variable to it, the variable is valid and has a textbox value, the textbox.text field is updated for both and can be seen on the screen for both, but only the double click function will update the database when the Accept button is pressed? Why does the measure button call fail?

Too weird for me, I have no clue, I need help!
Posted

1 solution

Okay, gave up. No ideas so rather than writing to the textbox.text value, I wrote to the underlying class which bound the DataContext field using CallByName.

VB
Dim mystring As String
       mystring = measure_current_textbox.DataBindings.Item(0).BindingMemberInfo.BindingField.ToString
       CallByName(_ts_collimationrecord, mystring, CallType.Set, 5.000)


used this in my test measurement, works every time for all calls.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900