Link to home
Start Free TrialLog in
Avatar of developer2012
developer2012

asked on

TextBox control can not be converted to value system.windows.controls.button

Hi everyone,

I have the below logic for increment and decrement button in vb.net.

 Private Sub IncrementBox(ByVal sender As TextBox)
        Dim value As Integer

        If Integer.TryParse(sender.Text, value) Then
            sender.Text = (value + 1).ToString()
        End If
    End Sub

Open in new window


And I am calling the functions on the event handler something like that:

 Private Sub btnDown_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnDown.Click
        IncrementBox((DirectCast(sender, TextBox)))
    End Sub

Open in new window


On the runtime it gives me an exception system.windows.textbox can not be converted to system.windows.button.

Any idea how to resolve it Please?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want to do this dynamically for more than one button you could try the following

Private Sub btnDown_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnDown.Click
        IncrementBox(Me.Controls.Find("textboxname", true))
    End Sub

Open in new window

Where textboxname is substituted for a name made up of a combination of the button clicked name and a constant so you relate button to text box

Button = button1
TextBox = button1_text
Avatar of developer2012
developer2012

ASKER

Thanks =))