Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you need is probably an OrderedDictionary, though other methods are also possible. I wouldn't go for a Hashtable, because that's unordered and requires quite a bit more coding to get ordering information in.</p> <p>Use the following to fill an <code>OrderedDictionary</code> (I assumed WinForms buttons, but ASP.NET or other buttons would also work):</p> <pre><code>// I assume your buttons are created somewhere // or already exist, i.e., they look something like: Button MondayXXXButton = new Button(); MondayXXXButton.Name = "MondayXXXButton"; MondayXXXButton.Text = "Hello world"; OrderedDictionary buttons = new OrderedDictionary(); buttons.Add(MondayXXXButton.Name, MondayXXXButton); // etc: for each button </code></pre> <p>Note: you can add the buttons automatically by looping through all controls. </p> <p>Then, you can use the following method to find the location of the next ordered item (unfortunately, you cannot get the "next item" without looping, you'll have to write your own ordered list if you need that):</p> <pre><code>Button GetNextButton(OrderedDictionary buttons, string searchThis) { IEnumerator enumerator = buttons.Keys.GetEnumerator(); for (enumerator.Reset(); enumerator.MoveNext(); ) if (enumerator.Current == searchThis) break; // if false, nothing was found, or last item was found if (enumerator.MoveNext()) return (Button)enumerator.Current; else return null; } </code></pre> <p>Finally, use this to get a certain button and retrieve the next one:</p> <pre><code>Button someButton = (Button) buttons["MondayYYYButton"]; Button nextButton = GetNextButton(buttons, "MondayYYYButton"); </code></pre> <p>The advantage of using an OrderedDictionary is that you shouldn't worry about how you add the items, they'll be ordered for you.</p> <p><strong><em>Update:</strong> slightly expanded explanation</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload