Click here to Skip to main content
16,005,162 members
Home / Discussions / C#
   

C#

 
GeneralRe: array of integers C++/C# Pin
#realJSOP26-Sep-07 5:58
professional#realJSOP26-Sep-07 5:58 
GeneralRe: array of integers C++/C# Pin
led mike26-Sep-07 7:25
led mike26-Sep-07 7:25 
QuestionProcess.GetProcesses(); fail Pin
H.R26-Sep-07 3:14
H.R26-Sep-07 3:14 
AnswerRe: Process.GetProcesses(); fail Pin
Pete O'Hanlon26-Sep-07 4:07
mvePete O'Hanlon26-Sep-07 4:07 
QuestioncheckBox & TreeView Pin
half-life26-Sep-07 3:12
half-life26-Sep-07 3:12 
AnswerRe: checkBox & TreeView Pin
TJoe26-Sep-07 3:28
TJoe26-Sep-07 3:28 
GeneralRe: checkBox & TreeView Pin
half-life26-Sep-07 3:42
half-life26-Sep-07 3:42 
QuestionWho am I? Detecting the "current" control for a handler [modified] Pin
JoeRip26-Sep-07 2:31
JoeRip26-Sep-07 2:31 
In one of my projects, I have a form with a grid of controls on it. I create the controls on the fly, as there are a dynamic number of them. To keep track of the controls, I keep them in a ArrayList.

As I create each control, I bind a handler to it, to handle events.

So:

ArrayList aMembersComboBoxes = new ArrayList();<br />
ArrayList aRelationshipComboBoxes = new ArrayList();<br />
...<br />
aMembersComboBoxes.Insert(iPosition, new System.Windows.Forms.ComboBox());<br />
aRelationshipComboBoxes.Insert(iPosition, new System.Windows.Forms.ComboBox());<br />
...<br />
((ComboBox)aMembersComboBoxes[iPosition]).SelectedIndexChanged += new EventHandler(cmbMembers_SelectIndexChanged);<br />
((ComboBox)aRelationshipComboBoxes[iPosition]).SelectedIndexChanged += new EventHandler(cmbRelationship_SelectIndexChanged);<br />


In the handler for my first combobox (cmbMembers) I change the DataSource for my second combobox (cmbRelationship), based on the selection the user makes in the first combobox.

<br />
private void cmbRelationship_SelectIndexChanged(object sender, EventArgs e)<br />
{<br />
// get the index of this control in it's ArrayList, so I can use it to refer to other controls in this line<br />
int i = aMembersComboBoxes.IndexOf((ComboBox)sender);<br />
<br />
if (((ComboBox)sender).SelectedItem.ToString().Contains("String"))<br />
{<br />
((ComboBox)aRelationshipComboBoxes[i]).DataSource = aRelationshipList_Strings;<br />
}<br />
}<br />


In this handler, the code works fine, because sender turns out to be the control I clicked on. But in the handler for the second combobox, the same code fails:

private void cmbRelationship_SelectIndexChanged(object sender, EventArgs e)<br />
{<br />
    // get the index of this control in it's ArrayList, so I can use it to refer to other controls in this line<br />
    int i = aRelationshipComboBoxes.IndexOf((ComboBox)sender);<br />
}<br />


Because in this case, "sender" turns out to be the control that initiated the action (the code executing in cmbMember), not the control that received it.

How can I get the identity of the control that is RECEIVING the event, the one for whom the handler is firing?

Thanks in advance.


-- modified at 8:39 Wednesday 26th September, 2007
AnswerRe: Who am I? Detecting the "current" control for a handler Pin
Malcolm Smart26-Sep-07 2:35
Malcolm Smart26-Sep-07 2:35 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
JoeRip26-Sep-07 2:41
JoeRip26-Sep-07 2:41 
AnswerRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
TJoe26-Sep-07 2:48
TJoe26-Sep-07 2:48 
GeneralRe: Who am I? Detecting the &amp;amp;quot;current&amp;amp;quot; control for a handler Pin
JoeRip26-Sep-07 2:52
JoeRip26-Sep-07 2:52 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
TJoe26-Sep-07 3:01
TJoe26-Sep-07 3:01 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
JoeRip26-Sep-07 3:07
JoeRip26-Sep-07 3:07 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
TJoe26-Sep-07 3:16
TJoe26-Sep-07 3:16 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
JoeRip26-Sep-07 3:18
JoeRip26-Sep-07 3:18 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
JoeRip26-Sep-07 3:21
JoeRip26-Sep-07 3:21 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
TJoe26-Sep-07 3:25
TJoe26-Sep-07 3:25 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
JoeRip26-Sep-07 3:34
JoeRip26-Sep-07 3:34 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
TJoe26-Sep-07 3:42
TJoe26-Sep-07 3:42 
GeneralRe: Who am I? Detecting the &amp;amp;quot;current&amp;amp;quot; control for a handler Pin
Luc Pattyn26-Sep-07 3:58
sitebuilderLuc Pattyn26-Sep-07 3:58 
GeneralRe: Who am I? Detecting the &amp;quot;current&amp;quot; control for a handler Pin
TJoe26-Sep-07 3:22
TJoe26-Sep-07 3:22 
QuestionHow to extract HTML code From any webpage using C#.Net Pin
allivelu26-Sep-07 1:35
allivelu26-Sep-07 1:35 
AnswerRe: How to extract HTML code From any webpage using C#.Net Pin
Christian Graus26-Sep-07 1:46
protectorChristian Graus26-Sep-07 1:46 
AnswerRe: How to extract HTML code From any webpage using C#.Net Pin
Matthew Cuba26-Sep-07 2:00
Matthew Cuba26-Sep-07 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.