{"id":1003,"date":"2009-11-07T08:00:00","date_gmt":"2009-11-07T08:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2009\/11\/07\/linking-zune-media-items-with-linq-part-2-matt-gertz\/"},"modified":"2024-07-05T12:42:26","modified_gmt":"2024-07-05T19:42:26","slug":"linking-zune-media-items-with-linq-part-2-matt-gertz","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/linking-zune-media-items-with-linq-part-2-matt-gertz\/","title":{"rendered":"Linking Zune media items with LinQ, Part 2 (Matt Gertz)"},"content":{"rendered":"<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">In this post, I&rsquo;ll continue on with coding the new playlist shuffler.<span>&nbsp; <\/span>If you haven&rsquo;t read <\/font><a href=\"http:\/\/blogs.msdn.com\/vbteam\/archive\/2009\/11\/06\/linking-zune-media-items-with-linq-part-1-matt-gertz.aspx\"><font color=\"#0000ff\" size=\"3\" face=\"Calibri\">part 1<\/font><\/a><font size=\"3\"><font face=\"Calibri\"> yet, I highly recommend it so that this post will make more sense. <\/font><span><span>J<\/span><\/span><\/font><\/p>\n<h2><font color=\"#4f81bd\" size=\"4\" face=\"Cambria\">Code for the controls (continued)<\/font><\/h2>\n<h3><font color=\"#4f81bd\" size=\"3\" face=\"Cambria\">The Title TextBox<\/font><\/h3>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">When the title changes, we&rsquo;ll want to indicate that the playlist has changed, and we&rsquo;ll want to cache the change and update the menus.<span>&nbsp; <\/span>This is pretty simple:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><span>Private<\/span> <span>Sub<\/span> edtTitle_TextChanged(<span>ByVal<\/span> sender <span>As<\/span> System.Object, <span>ByVal<\/span> e <span>As<\/span> System.EventArgs) <span>Handles<\/span> edtTitle.TextChanged<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>playlistTitle = edtTitle.Text<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>FileChanged = <span>True<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ResetMenus()<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><span>End<\/span> <span>Sub<\/p>\n<p><\/span><\/span><\/p>\n<h3><font color=\"#4f81bd\" size=\"3\" face=\"Cambria\">The ListBox<\/font><\/h3>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">The listbox has only two events that we need to handle.<span>&nbsp; <\/span>The first is just handling whenever the selection changes &ndash; we&rsquo;ll have to update the buttons in such a case:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><span>Private<\/span> <span>Sub<\/span> ListBox1_SelectedIndexChanged(<span>ByVal<\/span> sender <span>As<\/span> <span>Object<\/span>, _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>ByVal<\/span><span> e <span>As<\/span> System.EventArgs) <span>Handles<\/span> ShuffleListBox.SelectedIndexChanged<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ResetButtons()<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><span>End<\/span> <span>Sub<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">The other event is the DrawItem event, which is called whenever a listbox element needs to be draw.<span>&nbsp; <\/span>Normally, this event is handled by the base class, but for this application, we&rsquo;ll handle it so that we can decorate items which are linked.<span>&nbsp; <\/span>(We set this up by setting the DrawMode property of the listbox to OwnerDrawFixed.) Now, it even gets called when the listbox is empty, in order to draw the focus rectangle or whatever else should go into an empty list.<span>&nbsp; <\/span>Drawing isn&rsquo;t too difficult.<span>&nbsp; <\/span>First, I&rsquo;ll let it draw the background as usual:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><span>Private<\/span> <span>Sub<\/span> ShuffleListBox_DrawItem(<span>ByVal<\/span> sender <span>As<\/span> <span>Object<\/span>, _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>ByVal<\/span><span> e <span>As<\/span> System.Windows.Forms.DrawItemEventArgs) _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Handles<\/span><span> ShuffleListBox.DrawItem<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>e.DrawBackground()<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">Then, assuming that the index is non-zero and we actually have some text, we&rsquo;ll check to see if the item is linked.<span>&nbsp; <\/span>Anything linked with be written in bold, with the header node written in green, the tail node written in red, and anything in-between written in blue.<span>&nbsp; <\/span>The default, however, will be black text:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>If<\/span> e.Index &gt;= 0 <span>Then<\/span> <span><\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>Dim<\/span> myBrush <span>As<\/span> Brush = Brushes.Black<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">which we will use if there are no links involved:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>If<\/span> elem.NextLinkedElement <span>Is<\/span> <span>Nothing<\/span> <span>AndAlso<\/span> elem.PrevLinkedElement <span>Is<\/span> <span>Nothing<\/span> <span>Then<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>e.Graphics.DrawString(ShuffleListBox.Items(e.Index).ToString(), _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>e.Font, myBrush, e.Bounds, StringFormat.GenericDefault)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">but if there are links, we&rsquo;ll have to use a bold font:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>Else<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>Dim<\/span> linkFont <span>As<\/span> Font = <span>New<\/span> Font(e.Font.Name, e.Font.Size, _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>FontStyle.Bold, e.Font.Unit)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">and set the colors appropriately:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>If<\/span> elem.NextLinkedElement <span>IsNot<\/span> <span>Nothing<\/span> _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>AndAlso<\/span><span> elem.PrevLinkedElement <span>Is<\/span> <span>Nothing<\/span> <span>Then<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>myBrush = Brushes.Green <span>&#8216; Starting items are green<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>ElseIf<\/span> elem.NextLinkedElement <span>IsNot<\/span> <span>Nothing<\/span> _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>AndAlso<\/span><span> elem.PrevLinkedElement <span>IsNot<\/span> <span>Nothing<\/span> <span>Then<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>myBrush = Brushes.Blue <span>&#8216; Middle items are blue<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>ElseIf<\/span> elem.NextLinkedElement <span>Is<\/span> <span>Nothing<\/span> _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>AndAlso<\/span><span> elem.PrevLinkedElement <span>IsNot<\/span> <span>Nothing<\/span> <span>Then<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&amp;\nnbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>myBrush = Brushes.Red <span>&#8216; End items are red<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>End<\/span> <span>If<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>e.Graphics.DrawString(ShuffleListBox.Items(e.Index).ToString(), _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>linkFont, myBrush, e.Bounds, StringFormat.GenericDefault)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>End<\/span> <span>If<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>End<\/span> <span>If<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">Finally, regardless of what we drew, we&rsquo;ll need to draw the focus rectangle (and dotted line around any selections:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>e.DrawFocusRectangle()<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><span>End<\/span> <span>Sub<\/p>\n<p><\/span><\/span><\/p>\n<h3><font color=\"#4f81bd\" size=\"3\" face=\"Cambria\">The Link and Unlink buttons<\/font><\/h3>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">I&rsquo;ve been chattering a lot about linked files, but without walking through the process of actually linking them, it may be hard to see how they work in practice.<span>&nbsp; <\/span>When Link is chosen, we&rsquo;ll take all of the selected files, move them together, and point them at each other as a doubly-linked list.<span>&nbsp; <\/span>We can then use the existence of these links to change the behavior the program when drawing the items (as we have already done), shuffling them, or even saving them (more on that later). <\/font><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">To link the files, first we need to know how many:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><span>Private<\/span> <span>Sub<\/span> LinkBtn_Click(<span>ByVal<\/span> sender <span>As<\/span> System.Object, _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>ByVal<\/span><span> e <span>As<\/span> System.EventArgs) <span>Handles<\/span> LinkBtn.Click<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>Dim<\/span> numToLink <span>As<\/span> <span>Integer<\/span> = ShuffleListBox.SelectedItems.Count<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">Then, we need to iterate through each of those and link them.:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>For<\/span> index <span>As<\/span> <span>Integer<\/span> = 0 <span>To<\/span> numToLink &#8211; 1<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>Dim<\/span> elem <span>As<\/span> xmlMediaEntry = ShuffleListBox.SelectedItems(index)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>elem.NextLinkedElement = <span>If<\/span>(index &lt;&gt; numToLink &#8211; 1,_<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;<\/span><span>CType<\/span>(ShuffleListBox.SelectedItems(index + 1), xmlMediaEntry), _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Nothing<\/span><span>)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>elem.PrevLinkedElement = <span>If<\/span>(index &lt;&gt; 0, _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>CType<\/span><span>(ShuffleListBox.SelectedItems(index &#8211; 1), _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>xmlMediaEntry), <span>Nothing<\/span>)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><font size=\"3\"><font face=\"Calibri\">Note that I am using the If() ternary function above, which takes three arguments.<span>&nbsp; <\/span>The first is the condition to test, the second is code to run if the condition is true, and the third is code to run if the condition is false.<span>&nbsp; <\/span>In this case, I&rsquo;m checking to see if we are at the first or last of the selected items, and linking accordingly.<span>&nbsp; <\/span>Since header nodes shouldn&rsquo;t have a &ldquo;previous&rdquo; and tail nodes shouldn&rsquo;t have a &ldquo;next&rdquo;, I set these to Nothing under those conditions &ndash; otherwise, they are set to reference the adjacent node in the appropriate direction.<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font size=\"3\"><font face=\"Calibri\">Now, I want to physically move the linked tracks together so that they will actually play together.<span>&nbsp; <\/span>I&rsquo;ll get the first one where it is, and move the others up right behind it.<span>&nbsp; <\/span>I do this by removing them from the listbox and adding them back in at the right spot, and then remind the listbox that they should still be selected:<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>If<\/span> index &lt;&gt; 0 <span>Then<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShuffleListBox.Items.RemoveAt(ShuffleListBox.SelectedIndices(index))<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShuffleListBox.Items.Insert(ShuffleListBox.SelectedIndices(index &#8211; 1) + 1, elem)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShuffleListBox.SetSelected(ShuffleListBox.SelectedIndices(index &#8211; 1) + 1, <span>True<\/span>)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span>End<\/span> <span>If<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>Next<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><font size=\"3\"><font face=\"Calibri\">Be careful here; we are making two assumptions in all of this.<span>&nbsp; <\/span>First, we will be assuming that the list of selected indices is ordered from lowest to highest, and also that the list of selected objects is in the same order as the selected indices (although we could work around the latter point).<span>&nbsp; <\/span>These are safe assumptions to make, as near as I can tell.<span>&nbsp; <\/span>Second, we need to remember that the contents of SelectedIndices are indices into the Items() collection &ndash; that is, the contents of the 0<sup>th<\/sup> index of the SelectedIndices might refer to the 4<sup>th<\/sup> entry of Items() &ndash; that can get confusing.<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><font size=\"3\" face=\"Calibri\">Anyway, once we&rsquo;ve moved them together and linked them, we need to tell the listbox to repaint so that it redraws the linked items appropriately.<span>&nbsp; <\/span>To do this, we invalidate the control, and then tell it to update the invalidated regions:<\/font><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShuffleListBox.Invalidate()<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span><\/span><\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I&rsquo;ll continue on with coding the new playlist shuffler.&nbsp; If you haven&rsquo;t read part 1 yet, I highly recommend it so that this post will make more sense. J Code for the controls (continued) The Title TextBox When the title changes, we&rsquo;ll want to indicate that the playlist has changed, and we&rsquo;ll [&hellip;]<\/p>\n","protected":false},"author":258,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[22,195],"tags":[94,101,166,185],"class_list":["post-1003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-matt-gertz","category-visual-basic","tag-linqvb9","tag-matt-gertz","tag-vb2008","tag-xml"],"acf":[],"blog_post_summary":"<p>In this post, I&rsquo;ll continue on with coding the new playlist shuffler.&nbsp; If you haven&rsquo;t read part 1 yet, I highly recommend it so that this post will make more sense. J Code for the controls (continued) The Title TextBox When the title changes, we&rsquo;ll want to indicate that the playlist has changed, and we&rsquo;ll [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/1003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/258"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=1003"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/1003\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=1003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=1003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=1003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}