Add Handler to Dynamically Added ComboBox WPF

Posted on 2013-10-02
Medium Priority
Last Modified: 2013-10-15
I have added a couple dynamic ComboBox controls.  I want to add a handler to each of them for the SelectionChanged event.  However, intellisense tells me 'no way, José' to the following line:

 cbScore.AddHandler(cbScore.SelectionChanged += new EventHandler(cbScore_SelectionChanged);

Open in new window

All I want to do is add a handler so that if the selection is not -1 the background is white.

I already have a method that colors them red if they have no selection:

for (int i = 0; i < zone1; i++)

    if (((LogicalTreeHelper.FindLogicalNode(gridQuestion, "cbScoreSep" + i) as ComboBox).SelectedIndex) == -1)
        (LogicalTreeHelper.FindLogicalNode(gridQuestion, "cbScoreSep" + i) as ComboBox).Background = new SolidColorBrush(Colors.Red);

Open in new window

Maybe my syntax is wrong.  I am trying to make the move to C# from VB.  Still a bit lost.

Thanks for any help on this.
Question by:G Scott
1 Comment
LVL 35

Accepted Solution

sarabande earned 2000 total points
ID: 39556339
cbScore.AddHandler(cbScore.SelectionChanged += new EventHandler(cbScore_SelectionChanged);
the syntax is wrong. you have two opening parantheses but only one closing. the += operation is invalid also.

are you working in c++ or c#?

samples for both you find at



Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
In the video, one can understand the process of resizing images in single or bulk. Kernel Bulk Image Resizer is an easy to use tool for resizing large number of images. One can add and resize multiple images with this tool in single go. The video sh…

627 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