{"id":183,"date":"2010-04-28T07:35:20","date_gmt":"2010-04-28T07:35:20","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=183"},"modified":"2022-02-17T06:24:05","modified_gmt":"2022-02-17T06:24:05","slug":"using-list-box","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/list-box\/using-list-box","title":{"rendered":"Using ListBox"},"content":{"rendered":"<h5>\nList Box With More Options<br \/>\n<\/h5>\n<p>\nNeed columns, colouring, icons etc? Use a List View\n<\/p>\n<h4>\nCreating a List Box<br \/>\n<\/h4>\n<p>\nSelectionMode &#8211; Decide how many lines may be selected at a time by the user<br \/>\nMultiColumn &#8211; Not what you think! A multicolumn ListBox places items into as many columns as are needed to make vertical scrolling unnecessary.<br \/>\nSorted &#8211; Allows the list to be automatically sorted<br \/>\nText &#8211; Read to get currently selected item, write to cause it to move to matching item\n<\/p>\n<h4>\nErasing the contents of a List Box<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tlstMySelectOptions-&gt;Items-&gt;Clear();\r\n<\/code><\/pre>\n<h4>\nErasing Individual Items In A List Box<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\twhile (lstMySelectOptions-&gt;Items-&gt;Count)\r\n\t\tlstMySelectOptions-&gt;Items-&gt;RemoveAt(0);\t\/\/(RemoveAt works on index number)\r\n<\/code><\/pre>\n<h4>\nAdding items to a List Box<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tlstMySelectOptions-&gt;BeginUpdate();\t\t\/\/Stop painting of the ListBox as items are added\r\n\tlstMySelectOptions-&gt;Items-&gt;Add(&quot;Item A&quot;);\r\n\tlstMySelectOptions-&gt;Items-&gt;Add(&quot;Item B&quot;);\r\n\tlstMySelectOptions-&gt;EndUpdate();\r\n<\/code><\/pre>\n<h4>\nGetting Currently Selected Item<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tif (lstMySelectOptions-&gt;SelectedIndex &gt;= 0)\t\t\/\/Ensure a list item is selected (-1 if not)\r\n\t{\r\n\t\tUserId = lstMySelectOptions-&gt;SelectedIndex;\r\n<\/code><\/pre>\n<h4>\nSelecting Items<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n   lstMySelectOptions-&gt;SetSelected(1, true);\r\n   lstMySelectOptions-&gt;SetSelected(3, true);\r\n   lstMySelectOptions-&gt;SetSelected(5, true);\r\n<\/code><\/pre>\n<h4>\nColouring Items<br \/>\n<\/h4>\n<p>\nUse a ListView instead &#8211; gives full options over each item in the list.\n<\/p>\n<h4>\nDouble Click<br \/>\n<\/h4>\n<p>\nThe double click point will be the current selectedindex\n<\/p>\n<pre>\r\n<code>\r\n\tprivate: System::Void lstResults_MouseDoubleClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)\r\n\t{\r\n\t\tbtnViewData_Click(this, gcnew EventArgs());\r\n\t}\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>List Box With More Options Need columns, colouring, icons etc? Use a List View Creating a List Box SelectionMode &#8211; Decide how many lines may be selected at a time by the user MultiColumn &#8211; Not what you think! A multicolumn ListBox places items into as many columns as are needed to make vertical scrolling [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-183","post","type-post","status-publish","format-standard","hentry","category-list-box"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/183","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=183"}],"version-history":[{"count":8,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":1444,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/183\/revisions\/1444"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}