Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Neither - provide a centralized service which can decide which mechanism to use, then the application doesn't care, and you are free to choose hardcoding, sliding window or database mechanisms.</p> <p>To expand, typically, I would do something like this:</p> <ol> <li>Define <code>IPopulatableYear</code> interface which has a single <code>AddYear</code> method taking an int and constructing an appropriate <code>ListItem</code> or whatever.</li> <li>Make <code>MyYearListBox</code> inherit from regular <code>ListBox</code> implement <code>IPopulatableYear</code> (this works for winForms or WebForms)</li> <li>Create static method or singleton or method in your DAL or whatever.</li> </ol> <p>Like this:</p> <pre><code>PopulateYears(IPopulatableYear pl) { // Very simple implementation - change at will for (int lp = 2009 ; lp &lt; 2009 + 10 ; lp++) { pl.Add(lp); } } </code></pre> <p>or</p> <pre><code>PopulateYears(IPopulatableYear pl) { // A DB implementation SQLDataReader dr = DAL.YearSet() ; // Your choice of mechanism here while ( dr.Read() ) { pl.Add(dr[YEAR]); } } </code></pre> <p>or</p> <pre><code>PopulateYears(IPopulatableYear pl) { // A DB limits implementation with different ranges defined in database by key - key determined by control itself - IPopulatableYear needs to implement a .YearSetKey property SQLDataReader dr = DAL.YearLimits(pl.YearSetKey) ; // Your choice of mechanism here for ( int lp = dr[YEAR_MIN] ; lp &lt;= dr[YEAR_MAX] ; lp++ ) { pl.Add(lp); } } </code></pre> <p>The mechanism is now centrally managed.</p> <p>Use <code>MyYearListBox</code> on your forms and call <code>PopulateYears()</code> on it. If your forms are smart, they can detect all <code>MyYearListBox</code> instances and call it, so you no longer have any new code - just drag it on.</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