Solved

500pts: Getting the ID from sender in event?

Posted on 2006-06-12
1
249 Views
Last Modified: 2010-04-16
Hi there,

Can anybody help?

I have an event (click) that i have assigned to lots of Checkboxes.

And in that click evetn... i wil to add the name to of the item that was Checked or unchecked to a listbox

But how do i know which control was clicked as they all share the same event... i thought it might be the sender (see below)

            private void uxFieldsCheckBox_CheckedChanged(object sender, System.EventArgs e)
            {
                  ListBox test = new(ListBox)sender;
                  
                  // uxOrderListBox.Items.Add(  
            }

Thanks in advance ...

Ian
0
Comment
Question by:ianinspain
[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
1 Comment
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 16885988
Well, you're close, but is the sender is a CheckBox, it should be:

          private void uxFieldsCheckBox_CheckedChanged(object sender, System.EventArgs e)
          {
               CheckBox test = sender as CheckBox;
               if (test != null)
               { // is is indeed a CheckBox
                 
                 uxOrderListBox.Items.Add(test.Text);
               }
          }
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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