<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Listbox &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/listbox/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Wed, 07 May 2025 14:28:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Year of Code 2025: April Project, User Interface</title>
		<link>https://blog.xojo.com/2025/04/08/year-of-code-2025-april-project-user-interface/</link>
		
		<dc:creator><![CDATA[Gabriel Ludosanu]]></dc:creator>
		<pubDate>Tue, 08 Apr 2025 15:30:00 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Year of Code]]></category>
		<category><![CDATA[#YearofCode]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[Listbox]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[UI-Design]]></category>
		<category><![CDATA[User Interface]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=14788</guid>

					<description><![CDATA[April&#8217;s Year of Code theme is all about a great User Interface, I decided to focus on refining the user experience of an existing application.&#8230;]]></description>
										<content:encoded><![CDATA[
<p>April&#8217;s Year of Code theme is all about a great User Interface, I decided to focus on refining the user experience of an existing application. My project involves a user interface revamp of the familiar built-in ToDo desktop app example provided with Xojo.</p>



<p>The goal wasn&#8217;t to add new features but to explore how applying thoughtful UI design principles can significantly enhance the look and feel of an application, making it more visually appealing and cohesive.</p>



<p>Here are some of the key aspects of the UI revamp:</p>



<ul class="wp-block-list">
<li><strong>Design System Foundation:</strong>&nbsp;I started by establishing a basic design system. This involved defining core visual elements to ensure consistency across the entire application interface.</li>



<li><strong>Typography Definition:</strong>&nbsp;Specific styles were defined for how titles and standard text should appear. This helps create a clear visual hierarchy and improves readability.</li>



<li><strong>Consistent Color Palette:</strong>&nbsp;A specific set of colors (Light &amp; Dark mode) was chosen and implemented throughout the project, contributing to a unified and more polished look.</li>



<li><strong>Refined ListBox Appearance:</strong>&nbsp;The standard&nbsp;DesktopListBox&nbsp;control received some visual tweaks to better align with the overall updated aesthetic.</li>
</ul>



<p>The aim was to demonstrate how focusing on UI details can elevate even a simple example application.</p>



<p>Here’s a glimpse of the revamped ToDo app:</p>



<figure class="wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex">
<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="602" height="452" data-id="14792" src="https://blog.xojo.com/wp-content/uploads/2025/04/ToDoOrig-1.jpg" alt="" class="wp-image-14792" srcset="https://blog.xojo.com/wp-content/uploads/2025/04/ToDoOrig-1.jpg 602w, https://blog.xojo.com/wp-content/uploads/2025/04/ToDoOrig-1-300x225.jpg 300w" sizes="(max-width: 602px) 100vw, 602px" /></figure>



<figure class="wp-block-image size-large"><img decoding="async" width="602" height="584" data-id="14793" src="https://blog.xojo.com/wp-content/uploads/2025/04/ToDoFresh-1.jpg" alt="" class="wp-image-14793" srcset="https://blog.xojo.com/wp-content/uploads/2025/04/ToDoFresh-1.jpg 602w, https://blog.xojo.com/wp-content/uploads/2025/04/ToDoFresh-1-300x291.jpg 300w" sizes="(max-width: 602px) 100vw, 602px" /></figure>
</figure>



<p>You can find the complete source code for this UI-enhanced <a href="https://github.com/xolabsro/ToDoFresh" data-type="link" data-id="https://github.com/xolabsro/ToDoFresh" target="_blank" rel="noreferrer noopener">ToDo app project on GitHub</a>. </p>



<p>Stay tuned for more exciting projects as we continue our Year of Code 2025 journey!</p>



<p><em>Gabriel is a digital marketing enthusiast who loves coding with Xojo to create cool software tools for any platform. He is always eager to learn and share new ideas!</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>



<p><strong>Year of Code Project</strong></p>



<ul class="wp-block-list">
<li><a href="https://blog.xojo.com/2025/01/09/year-of-code-2025-kickoff/">Year of Code: Kickoff</a></li>



<li><a href="https://blog.xojo.com/2025/01/15/year-of-code-2025-january-project/" target="_blank" rel="noreferrer noopener">January Project: Desktop Apps</a>&nbsp;|&nbsp;<a href="https://forum.xojo.com/t/year-of-code-2025-january-project-sharing/83927" target="_blank" rel="noreferrer noopener">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/02/11/year-of-code-2025-february-project/">February Project: Database Apps</a>&nbsp;|&nbsp;<a href="https://forum.xojo.com/t/2025-year-of-code-february" target="_blank" rel="noreferrer noopener">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/03/05/year-of-code-2025-march-project-web-apps/">March Project: Web Apps</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-march/84474?u=alyssa_foley">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/04/08/year-of-code-2025-april-project-user-interface/">April Project: User Interface</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-april-user-interface/84926">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/05/07/year-of-code-2025-may-project-mobile-apps/">May Project: Mobile Apps</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-may-is-mobile/85272">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/06/10/year-of-code-2025-june-project-cross-platform-code-class/">June Project: Code Sharing</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-june-is-code-sharing/85612">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/07/10/year-of-code-2025-july-project-charting/">July Project: Charting</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-july-is-charting/85896">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/08/07/year-of-code-2025-august-project-console-apps/">August Project: Console Apps</a> | <a href="https://forum.xojo.com/t/august-2025-year-of-code-console-apps/86203">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/09/08/year-of-code-2025-september-project-games/">September Project: Games</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-septgamer">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/10/13/year-of-code-2025-october-project-multi-platform-communication/">October Project: Multi-Platform</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-october-multi-platform-communication/86717">Forum Discussion</a></li>



<li><a href="https://blog.xojo.com/2025/11/10/year-of-code-2025-november-project-pdf-postcard-generator/">November Project: PDF</a> | <a href="https://forum.xojo.com/t/2025-year-of-code-november-pdf/86969">Forum Discussion</a></li>
</ul>



<p><strong>How to Play:</strong></p>



<p>Each month we&#8217;ll announce a new theme and share an example project of our own. Share your projects to the Xojo Forum thread for that month via GitHub (all the links you need are posted above ↑ ). Learn how to use <a href="https://blog.xojo.com/2024/04/02/using-xojo-and-github/">Xojo and GitHub</a>.</p>



<p><strong>The Prizes:</strong></p>



<p>Monthly winners get $100 at the Xojo store. Every month you submit a project is another chance to win the grand prize. The grand prize is $250 cash plus a Xojo Pro license and a year of GraffitiSuite and will be announce in December. Learn more about the <a href="https://blog.xojo.com/2025/01/09/year-of-code-2025-kickoff/#prizes">prizes</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Folder Contents in a Menu, Redux</title>
		<link>https://blog.xojo.com/2021/02/24/folder-contents-in-a-menu-redux/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 19:40:35 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[Listbox]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=8103</guid>

					<description><![CDATA[Since I was asked for a few enhancements, here's a quick update to my previous Folder Contents in a Menu post from earlier this week. Enhancements include: Display the requested folder in the menu.
Sort the folder contents.
Skip files that cannot be accessed.]]></description>
										<content:encoded><![CDATA[
<p>Since I was asked for a few enhancements, here&#8217;s a quick update to my previous <a href="https://blog.xojo.com/2021/02/23/folder-contents-in-a-menu/" data-type="post" data-id="8092">Folder Contents in a Menu post</a> from earlier this week.</p>



<p>The requested enhancements are:</p>



<ul class="wp-block-list"><li>Display the requested folder in the menu.</li><li>Sort the folder contents.</li><li>Skip files that cannot be accessed.</li></ul>



<p>To dive into these a bit more, right now when you request SpecialFolder.Documents, you see the contents of Documents. With a slight change, you can now see &#8220;Documents&#8221; as the top of the hierarchical menu.</p>



<p>The folder contents were previously shown in the default file system order, which seems pretty random. Now the files are sorted in alphabetical order.</p>



<p>Lastly, if you had any inaccessible files in your folder hierarchy, an IOException was raised (and not caught). Now any files that cause an IOException are skipped.</p>



<p>Here is the updated CreateFolderMenu method:</p>



<pre class="wp-block-preformatted">Private Function CreateFolderMenu(f As FolderItem, showRoot As Boolean = False) As MenuItem
   Var base As New MenuItem(f.Name, f)
   Var rootMenu As MenuItem
   If showRoot Then
     rootMenu = New MenuItem(f.Name, f)
   End If

   Var sortedFiles() As FolderItem
   Var sortedNames() As String

   For i As Integer = 0 To f.Count - 1
     Try
       Var child As FolderItem
       child = f.ChildAt(i)
       sortedFiles.Add(child)
       sortedNames.Add(child.Name)
     Catch e As IOException
       Continue // Skip any unavailable files
     End Try
   Next

   sortedNames.SortWith(sortedFiles)
   For Each child As FolderItem In sortedFiles
     If child.IsFolder Then
       base.AddMenu(CreateFolderMenu(child))
     Else
       Var m As New MenuItem(child.Name, child)
       base.AddMenu(m)
     End If
   Next

   If showRoot Then
     rootMenu.AddMenu(base)
     Return rootMenu
   End If

   Return base
 End Function</pre>



<p>You&#8217;ll notice a new parameter, <em>showRoot</em>. Pass in True to include the root folder name in the hierarchical menu.</p>



<p>The sorting demonstrates the use of the <a href="https://documentation.xojo.com/api/language/sort.htmlWith">SortWith command</a> which allows you to sort one array (in the case an array of file names) and keep another array (the array of actual FolderItems) correspondingly sorted.</p>



<p>The Try&#8230;Catch is used to catch an IOException on a file and then allows things to continue on to the next file. </p>



<p><a href="http://files.xojo.com/ExamplesForUsers/FolderMenu2.xojo_binary_project">Download the Project</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Folder Contents in a Menu</title>
		<link>https://blog.xojo.com/2021/02/23/folder-contents-in-a-menu/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Tue, 23 Feb 2021 10:00:00 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[Listbox]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=8092</guid>

					<description><![CDATA[A user on the forum asked how they might show folder contents in a PopupMenu. Since a PopupMenu is not hierarchical, that wasn't really an option. But an alternative would be to show the contents in a hierarchical menu. Here's how you can recurse through files and add them to a regular MenuItem.]]></description>
										<content:encoded><![CDATA[
<p>A user on the <a href="https://forum.xojo.com">Xojo Programming forum</a> asked how they might show folder contents in a PopupMenu. Since a PopupMenu is not hierarchical, that wasn&#8217;t really an option. But an alternative would be to show the contents in a hierarchical menu.</p>



<p>Here&#8217;s how you can recurse through files and add them to a regular <a href="https://documentation.xojo.com/api/language/me.htmlnuItem">MenuItem</a>:</p>



<pre class="wp-block-code"><code>Private Function CreateFolderMenu(f As FolderItem) as MenuItem
  Var base As New MenuItem(f.Name, f)
  For Each child As FolderItem In f.Children
    If child.IsFolder Then
      base.AddMenu(CreateFolderMenu(child))
    Else
      Var m As New MenuItem(child.Name, child)
      base.AddMenu(m)
    End If
  Next

  Return base
End Function</code></pre>



<p>You can call it like this:</p>



<pre class="wp-block-code"><code>Var startFolder As FolderItem = SpecialFolder.Documents
FolderMenu = CreateFolderMenu(startFolder) // Property FolderMenu As MenuItem</code></pre>



<p>And show the menu like this:</p>



<pre class="wp-block-code"><code>Var selectedFile As MenuItem = FolderMenu.Popup

If selectedFile &lt;&gt; Nil Then
  Label1.Text = FolderItem(selectedFile.Tag).NativePath
End If</code></pre>



<p><a href="http://files.xojo.com/ExamplesForUsers/FolderMenu.xojo_binary_project">Sample project download</a></p>



<p>Another alternative might be to show the folder in a hierarchical ListBox. An example project for that is included with the <a href="https://xojo.com/download/">Xojo download</a>: Examples/Files/FileBrowser</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Customize Your ListBox Headers</title>
		<link>https://blog.xojo.com/2020/09/08/customize-your-listbox-headers/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Tue, 08 Sep 2020 20:14:34 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Listbox]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=7432</guid>

					<description><![CDATA[Get the perfect sized header height to fit both your pictures and text.]]></description>
										<content:encoded><![CDATA[<p>Sure, Xojo 2020r1 introduces some long awaited and much requested features but it&#8217;s also got a lot of feature gems it in it like the ability to customize the ListBox headers!<span id="more-7432"></span></p>
<p>I&#8217;m sure this new feature will make your <a href="https://documentation.xojo.com/api/deprecated/listbox.html"><code>ListBox</code></a> shine thanks to the work of Xojo Engineer William Yu. &nbsp;Even better, you only need to implement a couple of events to make it happen!</p>
<p>Even if you don&#8217;t need to customize your ListBox headers right now, you are already benefitting from its related improvements in 2020r1! The header&#8217;s height will adjust on macOS to fit the text size to the font size of your choice (as it was doing already in previous releases both on Windows and Linux).</p>
<p><img decoding="async" class="alignnone size-large wp-image-7433" src="https://blog.xojo.com/wp-content/uploads/2020/09/ListboxHeadersA-1024x430.png" alt="" width="1024" height="430" srcset="https://blog.xojo.com/wp-content/uploads/2020/09/ListboxHeadersA-1024x430.png 1024w, https://blog.xojo.com/wp-content/uploads/2020/09/ListboxHeadersA-300x126.png 300w, https://blog.xojo.com/wp-content/uploads/2020/09/ListboxHeadersA-768x323.png 768w, https://blog.xojo.com/wp-content/uploads/2020/09/ListboxHeadersA.png 1280w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>In addition, now it is really easy to add any picture, background color and text combination you want to your headers too; and the way to do that is adding these two Event Handlers to the ListBox instance:</p>
<pre>HeaderBackgroundPaint(g As Graphics, column As Integer) as Boolean

HeaderContentPaint(g As Graphics, column As Integer) as Boolean</pre>
<p>Do these look familiar to you? They should! As you can see, the Event Handler signatures are like the ones for customizing the cells drawing:</p>
<pre>CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) as Boolean

CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) as Boolean</pre>
<p>You already know that the <code>"g"</code> <a href="https://documentation.xojo.com/api/graphics/graphics.html">Graphics</a> context are relative to each header with the (0,0) coordinate on the upper-left corner, while the <code>g.width</code> and <code>g.height</code> values are the width and height dimensions of the header itself. Thus, you can use any of the available <code>Graphic</code> methods and properties to put the content of your choice right there.</p>
<p>You can use FontSize from the attributes section in the Inspector Panel to set the Header cell height.&nbsp;Let&#8217;s say you want to draw some pictures that are 32px height, while you want to draw the header text in a 20 points font size. So, in this case, you would set 32 points as the Font Size for the ListBox and then set the Font Size to 20 points for the text size drawing, probably in the HeaderContentPaint Event Handler. Don&#8217;t forget to set the FontSize to any other desired value for the cell text drawn in the rows themselves!</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-7434 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2020/09/CustomizedHeaders.png" alt="" width="712" height="534" srcset="https://blog.xojo.com/wp-content/uploads/2020/09/CustomizedHeaders.png 712w, https://blog.xojo.com/wp-content/uploads/2020/09/CustomizedHeaders-300x225.png 300w" sizes="auto, (max-width: 712px) 100vw, 712px" /></p>
<p>As a result, you will get the perfect sized header height to fit both your pictures and text.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Lazy Loading Data with ListBox</title>
		<link>https://blog.xojo.com/2020/04/17/lazy-loading-data-with-listbox/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Fri, 17 Apr 2020 10:00:22 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Listbox]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6904</guid>

					<description><![CDATA[The ListBox is a great control for showing users lists of data, even data with lots and lots of rows. But the ListBox, being a&#8230;]]></description>
										<content:encoded><![CDATA[
<p>The ListBox is a great control for showing users lists of data, even data with lots and lots of rows. But the <a href="https://documentation.xojo.com/api/deprecated/listbox.html">ListBox</a>, being a UI control, is not meant to also be a container for hundreds of thousands of rows of data. It can take noticeable amount of time to to populate and you end up with your data being duplicated because it exists in both the ListBox and the original source (file, database or other data structure).</p>



<p>One way to avoid this problem is to not actually load all the data at once. This is often a great idea because the user can&#8217;t actually see all the data at once anyway. So why not only load the data they can actually see?</p>



<p>One way to do this is to use a <a href="https://documentation.xojo.com/api/deprecated/scrollbar.html">ScrollBar</a> to track the data the user wants to see and then to only load that data into the ListBox.</p>



<p>To demonstrate this, start by creating a simple class as a container for data. The class structure is like this:</p>



<pre class="wp-block-preformatted">Class ListData
  Property Num As Integer
  Property Value As Double
  Property Desc As String
End Class</pre>



<p>On Window1, add a property that is an array of this class:</p>



<pre class="wp-block-preformatted">Data() As ListData</pre>



<p>Now on Window1, add two Buttons, a Vertical Scroll Bar and a ListBox. Align the ScrollBar so that it is to the right of the ListBox and the same height and change its Allow Live Scrolling property to True (ON). Change the ListBox to have 3 columns using the Column Count property in the Inspector. In the Open event of the Window add 1 million elements to the Data array:</p>



<pre class="wp-block-preformatted"> For i As Integer = 1 To 1000000
   Var d As New ListData
   d.Num = i
   d.Value = Rnd()
   d.Desc = "Testing"
   Data.AddRow(d)
 Next</pre>



<p>In the Action event of the 1st Button, add this code to load the entire 1 million element array into the ListBox:</p>



<pre class="wp-block-preformatted">Listbox1.HasVerticalScrollbar = True
ScrollBar1.Visible = False
Listbox1.RemoveAllRows
For i As Integer = 0 To Data.LastRowIndex
  Listbox1.AddRow(Data(i).Num.ToString, Data(i).Value.ToString, Data(i).Desc)
Next</pre>



<p>Pretty standard stuff. Now in the 2nd Button&#8217;s Action event add this code, which populates the ListBox only with the first 50 rows:</p>



<pre class="wp-block-preformatted">Listbox1.RemoveAllRows
Listbox1.HasVerticalScrollbar = False
ScrollBar1.Visible = True
ScrollBar1.MinimumValue = 0
ScrollBar1.MaximumValue = Data.LastRowIndex
ScrollBar1.Value = 0
For i As Integer = 0 To 50
  Listbox1.AddRow(Data(i).Num.ToString, Data(i).Value.ToString, Data(i).Desc)
Next</pre>



<p>Lastly add the ValueChanged event to the ScrollBar with this code, which fetches 50 rows after the value of the ScrollBar:</p>



<pre class="wp-block-preformatted">Listbox1.RemoveAllRows
For i As Integer = Me.Value To Me.Value + 50
  If i &lt;= Data.LastRowIndex Then
    Listbox1.AddRow(Data(i).Num.ToString, Data(i).Value.ToString, Data(i).Desc)
  End If
Next</pre>



<p>Now go ahead and run the project. Click the first button to see how long it takes to populate the ListBox. It took my computer about 11 seconds. You can scroll around at a reasonable speed, although it&#8217;s a bit unwieldy with that many rows. Another thing to note is that this uses about 750MB of RAM.</p>



<p>Now click the second button that does the lazy loading. It will show the first bunch of rows instantly. Use the scrollbar to display other rows and you&#8217;ll see they are also displayed instantly even thought they are not technically in the ListBox. This also uses only about 110MB of RAM.</p>



<p>Now this is just a quick example (<a href="http://files.xojo.com/BlogExamples/ListBoxLazyLoad.xojo_binary_project.zip">download here</a>) and doesn&#8217;t handle every situation, but you can certainly expand on it as needed. If you&#8217;d rather not create this yourself, another option is to try 3rd party ListBox or DataView controls which have this built-in. You can find some on our 3rd Party Product page:</p>



<p><a href="https://documentation.xojo.com/Resources:3rd_Party_Products">https://documentation.xojo.com/Resources:3rd_Party_Products</a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
