Link to home
Start Free TrialLog in
Avatar of sainavya1215
sainavya1215

asked on

Vb.net Textbox Command Button

Windows form
============
I hve a windows form with 2 TextBoxes and 2 Cancel buttons. As a textboxes value can be cancelled .

I populate the data from the dataset (well i dont bind it as its not ncesssary)
in both the textboxes.  User can click cancel to cancel a value in textbox  where I update the database saying that line has been cancelled.
How would we know that if cancel button pressed corresponds to textbox1 or textbox2
 

Textbox1              cancelButton
Textbox2              cancelButton
Textbox3              cancelButton

Can a simple example be shown ? thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of arif_eqbal
arif_eqbal

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
Avatar of sainavya1215
sainavya1215

ASKER

yep....Undestood solution 1 ..........could it be more explained on solution 2.... Thanks for that
When an event handler is fired, it is passed an Object called "sender". This is the object that triggered the event.

If you know what type of object it is, you can use the CTYPE function to cast the generic Object into the object that triggered the event.

Solution 2 provided by arif_egbal simply says this:

Private Sub ButtonClicks(sender As Object, e as EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
    Select Case CType(sender, Button).Name     ' This determines WHAT button the user clicked.
        Case "Button1"

        Case "Button2"

        Case "Button3"


End Sub

This technique allows you to reduce code by using the same event handler to handle multiple events from objects on your form.

Hope that helps.