Solved

how to know which index of clicked in array of button

Posted on 2006-07-06
5
230 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now