?
Solved

how to know which index of clicked in array of button

Posted on 2006-07-06
5
Medium Priority
?
237 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 1600 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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 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