{"id":159,"date":"2016-02-18T18:03:52","date_gmt":"2016-02-18T18:03:52","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=159"},"modified":"2022-02-17T06:24:14","modified_gmt":"2022-02-17T06:24:14","slug":"using-listbox","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/list-box\/using-listbox","title":{"rendered":"Using ListBox"},"content":{"rendered":"<h5>\n\tList Box With More Options<br \/>\n<\/h5>\n<p>\n\tNeed columns, colouring, icons etc? Use a List View\n<\/p>\n<h4>\n\tCreating a List Box<br \/>\n<\/h4>\n<p>\n\tSelectionMode &#8211; Decide how many lines may be selected at a time by the user<br \/>\n\tMultiColumn &#8211; Not what you think! A multicolumn ListBox places items into as many columns as are needed to make vertical scrolling unnecessary.<br \/>\n\tSorted &#8211; Allows the list to be automatically sorted\n<\/p>\n<h4>\n\tErasing the contents of a List Box<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tlstMySelectOptions.Items.Clear();\r\n<\/code><\/pre>\n<h4>\n\tErasing Individual Items In A List Box<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\twhile (lstMySelectOptions.Items.Count)\r\n\t\tlstMySelectOptions.Items.RemoveAt(0);\t\/\/(RemoveAt works on index number)\r\n<\/code><\/pre>\n<h4>\n\tAdding items to a List Box<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tlstMySelectOptions.BeginUpdate();\t\t\/\/Stop painting of the ListBox as items are added\r\n\tlstMySelectOptions.Items.Add(&quot;Item A&quot;);\r\n\tlstMySelectOptions.Items.Add(&quot;Item B&quot;);\r\n\tlstMySelectOptions.EndUpdate();\r\n<\/code><\/pre>\n<h4>\n\tGetting Currently Selected Item<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tif (lstMySelectOptions.SelectedIndex &gt;= 0)\t\t\/\/Ensure a list item is selected (-1 if not)\r\n\t{\r\n\t\tUserId = lstMySelectOptions.SelectedIndex;\r\n<\/code><\/pre>\n<h4>\n\tSelecting Items<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n   lstMySelectOptions.SetSelected(1, true);\r\n   lstMySelectOptions.SetSelected(3, true);\r\n   lstMySelectOptions.SetSelected(5, true);\r\n<\/code><\/pre>\n<h4>\n\tColouring Items<br \/>\n<\/h4>\n<p>\n\tUse a ListView instead &#8211; gives full options over each item in the list.\n<\/p>\n<h4>\n\tDouble Click<br \/>\n<\/h4>\n<p>\n\t&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":[31],"tags":[],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-list-box"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":241,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/159\/revisions\/241"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}