Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanks for everyone's help on my prior questions. It's amazing how when one learns something the articles start to make more and more sense.

I no longer feel like kicking the cat (I like cat's, just a figure of speech) since I am making progress. However is there a simple way to pass the name of a control and then use it in the code behind ie:

Test.XAML

<ComboBox Name="cmbStatus" DropDownOpened="cmbControl_Open("cmbStatus")" ...

Then in the Test.XAML.cs I want to do something like:

private void cmbControl_Open(string strControlName)
{
combobox FoundBox = FindName(strControlName);
FoundBox.DisplayMemberPath = "Field";

I see lots of articles on getting a collection and then processing each member of the collection. Is there a more direct solution to the problem?

I am not making myself clear. Basically I have 10 comboboxes that each call a lookup table. I wanted to create a general event and pass it the name of the combobox, query, displaypath and valuepath. Then in the subroutine propogate the domainsource when the combobox drops down.

That way I have one event handling all of the combo boxes.

Can anyone tell me how to reply? Do I just hit answer?

Larry
Posted
Updated 22-Apr-10 8:03am
v3

You can't specify parameters on event handlers like that.

Since you know what control posted the event, you can simply rerfer to that control in the event handler.

private void cmbControl_Open(string strControlName)
{
    this.cmbStatus.DisplayMemberPath = "Field";
}
 
Share this answer
 
Hi Larry,

Why do you want to pass the control name as a parameter?
You can directly access the control inside your event handler.

C#
protected void cmbControl_Open(object sender, EventArgs e)
{
    cmbStatus.DisplayMemberPath = "Field";
}


Yup, if you are using the same event handler for multiple ComboBox, then also you can get the combobox very easily. You can notice that, your event handler has a sender. This is your specified combobox that you opened.

So, write the following code in that case:

C#
protected void cmbControl_Open(object sender, EventArgs e)
{
    ComboBox myCombo = sender as ComboBox;
    myCombo.DisplayMemberPath = "Field";
}


If this answers your query, please "Mark As Answer".
Thank you for posting at CodeProject.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900