Solved

how to know which index of clicked in array of button

Posted on 2006-07-06
5
235 Views
Last Modified: 2011-09-20
Hi experts,


I have created one runtime array of buttons

And i wish to know which button i have clicked i.e what is the index of button .

how to get particular index ?


Thanks in advance.
-Avinash
0
Comment
Question by:avinash_takale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 400 total points
ID: 17050660
Cast the sender parameter to a Button and look at it's Id (or Name if WinForms)

Button button = sendar as Button
if (button != null)
{
  string buttonName = button.Id;
}

If you want the actual numeric index from the array I would name the buttons with the index number (e.g. MyButton1, MyButton2) and parse it in the event handler.  Or, if it's a Windows app, you could use the Tag property.
0
 

Author Comment

by:avinash_takale
ID: 17051090
and one more thing if i want to set some click event on runtime checkbox
Then how do i set this ?

means i will read some value before start of application and i want to some check box to true in a array of checkbox which i have created at runtime
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 17051123
If you have a method already defined:

public void MyClick(object sender, EventArge args)
{
  // Do something
}


then use

CheckBox checkBox = new CheckBox();
/// set properties
checkBox.Click += new EventHandler(MyCLick);
0
 

Author Comment

by:avinash_takale
ID: 17051235


suppose there are 5 checkbox are created at runtime
and i want to set 2nd and 4th to true at the form startup
How do i set this true this cheakbox.

Thanks in advance
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 17051479
checkBox.Checked = true;
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# DateTime Format validation 4 86
What are MicroServices? 4 64
Timeouts during development 3 25
C#: How do I test for null objects and a dub a value? 2 32
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

731 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