{"id":153,"date":"2010-03-30T12:47:53","date_gmt":"2010-03-30T12:47:53","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=153"},"modified":"2022-02-17T06:24:05","modified_gmt":"2022-02-17T06:24:05","slug":"combo-box","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/combo-box\/combo-box","title":{"rendered":".Using Combo Boxes"},"content":{"rendered":"<h4>\nOnly permitting items in the list<br \/>\n<\/h4>\n<h5>\n(YOU HAVE TO REMEMBER TO DO THIS TO BLOCK USER ENTERING THEIR OWN VALUES)<br \/>\n<\/h5>\n<p>\nDropDownStyle = DropDownList (Only accepts strings that are part of the selection list)\n<\/p>\n<h4>\nLoading the contents of a comboBox at application startup<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tcmbMyComboBox-&gt;BeginUpdate();\r\n\tcmbMyComboBox-&gt;SelectedIndex = -1;\r\n\tcmbMyComboBox-&gt;Items-&gt;Clear();\t\t\/\/Remove Existing Items If Necessary\r\n\r\n\tfor (Count = 0; Count &lt;= 500; Count++)\t\/\/Add Items\r\n\t\tcmbMyComboBox-&gt;Items-&gt;Add((Count * 100) + &quot;mm&quot;);\r\n\r\n\tcmbMyComboBox-&gt;SelectedIndex = 0;\t\/\/Select default item\r\n\tcmbMyComboBox-&gt;EndUpdate();\r\n\r\n\t\/\/while (cmbMyComboBox-&gt;Items-&gt;Count)\t\/\/Another method to remove items\r\n\t\/\/\tcmbMyComboBox-&gt;Items-&gt;RemoveAt(0);\r\n<\/code>\r\n<\/pre>\n<h4>\nAllowing User To Type Text To Find An Entry<br \/>\n<\/h4>\n<p>\nDropDownStyle = DropDown<br \/>\nAutoCompleteMode = Append (or an alternative if preffered)<br \/>\nAutoCompleteSource = List Items<br \/>\nIn this mode the user can enter text that doesn&#39;t match an entry in the list. You need to detect this yourself. Unfortunately you can&#39;t use the &#39;Leave&#39; event of the combobox as if a user types the start of a name then uses tab to select it the SelectedIndex value is still -1 on the Leave call and only changes afterwards. You need to do the check using some other means.\n<\/p>\n<pre>\r\n<code>\r\n\tif (cmbUsername-&gt;SelectedIndex &lt; 0)\r\n\t\tcmbUsername-&gt;Text = &quot;&quot;;\r\n<\/code><\/pre>\n<h4>\nSelect An Item In the List<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tcmbMyComboBox-&gt;SelectedIndex = 0;\r\n<\/code><\/pre>\n<h4>\nGetting Currently Selected Item Text<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tMyString = cmbMyComboBox-&gt;Items[cmbMyComboBox-&gt;SelectedIndex]-&gt;ToString();\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Only permitting items in the list (YOU HAVE TO REMEMBER TO DO THIS TO BLOCK USER ENTERING THEIR OWN VALUES) DropDownStyle = DropDownList (Only accepts strings that are part of the selection list) Loading the contents of a comboBox at application startup cmbMyComboBox-&gt;BeginUpdate(); cmbMyComboBox-&gt;SelectedIndex = -1; cmbMyComboBox-&gt;Items-&gt;Clear(); \/\/Remove Existing Items If Necessary for (Count = [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-combo-box"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/153","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=153"}],"version-history":[{"count":13,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":1411,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/153\/revisions\/1411"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}