{"id":164,"date":"2010-03-30T18:50:04","date_gmt":"2010-03-30T18:50:04","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=164"},"modified":"2022-02-17T06:24:05","modified_gmt":"2022-02-17T06:24:05","slug":"using-safe_cast-to-access-the-object-that-triggered-an-event","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/safecast\/using-safe_cast-to-access-the-object-that-triggered-an-event","title":{"rendered":"Using safe_cast to access the object that triggered an event"},"content":{"rendered":"<h4>\nAn example using a single event triggered by multiple combo boxes<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\t\/\/Setting up combo boxes\r\n\tMyComboBox1-&gt;SelectedIndexChanged += gcnew System::EventHandler(this, &amp;frmMain::GeneralComboBox_SelectedIndexChanged);\r\n\tMyComboBox1-&gt;Tag = 1;\t\t\/\/In this example we use the tag property to store an ID we will use later\r\n\tMyComboBox2-&gt;SelectedIndexChanged += gcnew System::EventHandler(this, &amp;frmMain::GeneralComboBox_SelectedIndexChanged);\r\n\tMyComboBox2-&gt;Tag = 2;\r\n\tMyComboBox3-&gt;SelectedIndexChanged += gcnew System::EventHandler(this, &amp;frmMain::GeneralComboBox_SelectedIndexChanged);\r\n\tMyComboBox3-&gt;Tag = 3;\r\n\r\n\r\n\t\/\/Determining which combo box triggered the event\r\n\tprivate: System::Void GeneralComboBox_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e)\r\n\t{\r\n\t\tint TagIndexValue;\r\n\t\tSystem::Windows::Forms::ComboBox ^CallingComboBox = safe_cast&lt;system::windows::forms::combobox^&gt;(sender);\r\n\t\tTagIndexValue = Convert::ToInt32(CallingComboBox-&gt;Tag);\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>An example using a single event triggered by multiple combo boxes \/\/Setting up combo boxes MyComboBox1-&gt;SelectedIndexChanged += gcnew System::EventHandler(this, &amp;frmMain::GeneralComboBox_SelectedIndexChanged); MyComboBox1-&gt;Tag = 1; \/\/In this example we use the tag property to store an ID we will use later MyComboBox2-&gt;SelectedIndexChanged += gcnew System::EventHandler(this, &amp;frmMain::GeneralComboBox_SelectedIndexChanged); MyComboBox2-&gt;Tag = 2; MyComboBox3-&gt;SelectedIndexChanged += gcnew System::EventHandler(this, &amp;frmMain::GeneralComboBox_SelectedIndexChanged); MyComboBox3-&gt;Tag = 3; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-safecast"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":943,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/164\/revisions\/943"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}