[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Vb.net Textbox Command Button

Posted on 2004-11-24
3
Medium Priority
?
590 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:sainavya1215
3 Comments
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 1200 total points
ID: 12672675
You surely will have different names for the three Cancel Buttons
Say ButtonCancel_1, ButtonCancel_2 and so on

Solution 1:

Handle the Click events of the Cancel Buttons separately

so ButtonCancel_1 Click means textBox1 value was cancelled
 ButtonCancel_2 Click means textBox2 value was cancelled

Solution 2:

use a common Event handler for Click of all such cancel Buttons
Then use

CType(sender, Button).Name to identify the name of the Cancel Button that was clicked


0
 

Author Comment

by:sainavya1215
ID: 12676426
yep....Undestood solution 1 ..........could it be more explained on solution 2.... Thanks for that
0
 
LVL 14

Expert Comment

by:ptakja
ID: 12677226
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.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question