Deprecated: Creation of dynamic property GeneralSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Deprecated: Creation of dynamic property AbstractSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Deprecated: Creation of dynamic property UserSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_init_login.inc.php on line 81

Deprecated: Creation of dynamic property CollectionSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/inc/_core/_template.funcs.php on line 467

Deprecated: Creation of dynamic property ItemList2::$filterset_name is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemlistlight.class.php on line 114

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_param.funcs.php on line 1407

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_param.funcs.php on line 1407

Deprecated: Creation of dynamic property ItemQuery::$dbtablename is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 78

Deprecated: Creation of dynamic property ItemQuery::$dbprefix is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 79

Deprecated: Creation of dynamic property ItemQuery::$dbIDname is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 80

Deprecated: Creation of dynamic property ItemQuery::$Blog is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 231

Deprecated: Creation of dynamic property ItemQuery::$cat_array is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 232

Deprecated: Creation of dynamic property ItemQuery::$cat_modifier is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 233

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: Creation of dynamic property ItemQuery::$assignees_logins is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 525

Deprecated: Creation of dynamic property ItemQuery::$author_assignee is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 557

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: Creation of dynamic property ItemQuery::$m is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 842

Deprecated: Creation of dynamic property ItemQuery::$w is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 843

Deprecated: Creation of dynamic property Item::$objtype is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemlight.class.php on line 164

Deprecated: Creation of dynamic property Item::$datestart is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemlight.class.php on line 175

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/inc/_core/_template.funcs.php on line 40

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/inc/_core/_template.funcs.php on line 405

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/inc/_core/_template.funcs.php on line 406

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/inc/_core/_template.funcs.php on line 407

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/inc/_core/_template.funcs.php on line 408

Deprecated: Creation of dynamic property ItemQuery::$dbtablename is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 78

Deprecated: Creation of dynamic property ItemQuery::$dbprefix is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 79

Deprecated: Creation of dynamic property ItemQuery::$dbIDname is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 80

Deprecated: Creation of dynamic property ItemQuery::$Blog is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 231

Deprecated: Creation of dynamic property ItemQuery::$cat_array is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 232

Deprecated: Creation of dynamic property ItemQuery::$cat_modifier is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 233

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: Creation of dynamic property ItemQuery::$assignees_logins is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 525

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10535

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/_core/_misc.funcs.php on line 10540

Deprecated: Creation of dynamic property ItemQuery::$m is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 842

Deprecated: Creation of dynamic property ItemQuery::$w is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_itemquery.class.php on line 843

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/skins/_rss2/index.main.php on line 45

Warning: Cannot modify header information - headers already sent by (output started at /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php:121) in /home4/tylering/public_html/b2e/skins/_rss2/index.main.php on line 46
Switched Keys - Category: "Code Project" https://tylerhosting.com/b2e/dbell.php Switched Keys, the blogs of Dana Bell of Tyler, Texas en-US http://blogs.law.harvard.edu/tech/rss 60 Managing Localization in Combo Boxes https://tylerhosting.com/b2e/dbell.php/managing-localization-in-combo-boxes Wed, 18 Jan 2017 19:41:00 +0000 Dana Bell Information Technology Computing Code Project 377@https://tylerhosting.com/b2e/
Deprecated: Creation of dynamic property Item::$cache_has_content_parts is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_item.class.php on line 4911

Deprecated: Creation of dynamic property tinymce_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property calendar_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property calendar_plugin::$dbtable is deprecated in /home4/tylering/public_html/b2e/plugins/_calendar.plugin.php on line 53

Deprecated: Creation of dynamic property calendar_plugin::$dbprefix is deprecated in /home4/tylering/public_html/b2e/plugins/_calendar.plugin.php on line 54

Deprecated: Creation of dynamic property calendar_plugin::$dbIDname is deprecated in /home4/tylering/public_html/b2e/plugins/_calendar.plugin.php on line 55

Deprecated: Creation of dynamic property quicktags_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property auto_anchors_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property shortlinks_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property custom_tags_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property archives_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property archives_plugin::$dbtable is deprecated in /home4/tylering/public_html/b2e/plugins/_archives.plugin.php on line 54

Deprecated: Creation of dynamic property archives_plugin::$dbprefix is deprecated in /home4/tylering/public_html/b2e/plugins/_archives.plugin.php on line 55

Deprecated: Creation of dynamic property archives_plugin::$dbIDname is deprecated in /home4/tylering/public_html/b2e/plugins/_archives.plugin.php on line 56

Deprecated: Creation of dynamic property email_elements_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property financial_contribution_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property inlines_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property ping_b2evonet_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property ping_pingomatic_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property twitter_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property webmention_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property webmention_plugin::$ping_service_process_message is deprecated in /home4/tylering/public_html/b2e/plugins/webmention_plugin/_webmention.plugin.php on line 52

Deprecated: Creation of dynamic property webmention_plugin::$ping_service_setting_title is deprecated in /home4/tylering/public_html/b2e/plugins/webmention_plugin/_webmention.plugin.php on line 53

Deprecated: Creation of dynamic property autolinks_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property videoplug_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property auto_p_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property mermaid_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property texturize_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property nofollow_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property content_blocks_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property table_contents_plugin::$classfile_path is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_plugins.class.php on line 413

Deprecated: Creation of dynamic property Item::$renderers_validated is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_item.class.php on line 11107

Deprecated: Creation of dynamic property Item::$pages is deprecated in /home4/tylering/public_html/b2e/inc/items/model/_item.class.php on line 2412

Deprecated: Creation of dynamic property ItemSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121
<h2>Introduction</h2> <p>This example combines the use of combo boxes, a separate DataSource, and localized <code>string</code>s for alternate cultures.</p> <h2>Background</h2> <p>Using a combo box, programmers can use a selected item as a variable or parameter within a single method. In other cases, the combo box is a collection of options, each of which executes a different method. The combo box can be populated within the design, or assigned using a <code>DataSource</code>. Even a simple <code>string</code> array can be used for that. Processing the selection from the combo box when executing a different method for each combo box entry can be done using the index of the selected item.</p> <pre lang="cs">string[] special = { "Select", "Vowels", "DoubleI", "DoubleU", "NoVowels", "Consonants", "QNotU", "Palins", "HighFives", "HighFours", "NoHooks"}; cboSearch.DataSource = special; switch (cboSearch.SelectedIndex) { case 1: btnVowelHeavy_Click(sender, e); break; ... case 5: btnConsonantDumps_Click(sender, e); break; ... }</pre> <h2>An Alternate</h2> <p>When using the combo box selected index the routine may have to be modified each time a new item is added or items are moved around. If we add an item to the middle of the list, we have to figure out what the item number will be and then change the <code>select</code> statement. Case 2 may be the new one, so the original case 2 has to be changed to case 3, case 3 to case 4, etc.</p> <p>To avoid that, it is possible to use the selected item's content. Using the actual <code>string</code> in the collection is often a clearer way to code.</p> <pre lang="cs">switch(cboSearch.SelectedText) { case "Vowels": ...</pre> <p>Thus, case 1 would be replaced with case "<code>Vowels</code>". Additions to the collection will not require any reordering.</p> <h2>The Challenge</h2> <p>This works well until you have to support localization, that is, present different collections of <code>string</code>s based on the language selected. The <code>string</code> used in a <code>switch</code> statement must be a constant, so you can't use:</p> <pre lang="cs">switch (cboSearch.SelectedText) { case rm.GetString("Vowels"): ...</pre> <p>We could go back to using indexes, but we want to avoid going back to that. This is where the <code>CultureCombo</code> comes in handy. This simple class and the supporting method uses the characteristics of a combo box to create localized strings, while keeping the ability to process the selection using <code>string</code> identification.</p> <pre lang="cs">class CultureCombo { public string name {get; set;} public string display {get; set;} }</pre> <p>Next, you would incorporate the method that processes the array. Using this code, you can then apply that to the combo box.</p> <pre lang="cs">private List&lt;CultureCombo&gt; comboList(string[] termList) { List&lt;CultureCombo&gt; options = new List&lt;CultureCombo&gt;(); foreach (string word in termList) options.Add(new CultureCombo { name = word, display = rm.GetString(word) }); return options; }</pre> <p>The code assumes you have created a <code>ResourceManager</code> called <code>rm</code>. Replace <code>rm</code> above with whatever variable you used for the <code>ResourceManager</code>. In my code, it is represented with the code.</p> <pre lang="cs">Assembly myAssembly = typeof(Utilities).Assembly; ResourceManager rm = new ResourceManager("Hoot.Resources.Strings", myAssembly)</pre> <h2>Implementation</h2> <p>The first step to using this in a program is to create an array of <code>string</code> IDs, the <code>string</code> used to access the culture's translation. If you have incorporated localized <code>string</code>s, you would already have these. In my example:</p> <pre lang="cs">string[] special = { "Select", "Vowels", "DoubleI", "DoubleU", "NoVowels", "Consonants", "QNotU", "Palins", "HighFives", "HighFours", "NoHooks"};</pre> <p>Next, use the method to populate the combo box.</p> <pre lang="cs">searchOptions = comboList(special); cboSearch.ValueMember = "name"; cboSearch.DisplayMember = "display"; cboSearch.DataSource = searchOptions;</pre> <p>Finally, find the item in the list by looking at the <code>value</code> (or "<code>name</code>") of the combo box item:</p> <pre lang="cs">switch (cboSearch.SelectedValue.ToString()) { case "Vowels": btnVowelHeavy_Click(sender, e); break; case "Consonants": btnConsonantDumps_Click(sender, e); break; .. }</pre> <p>While the <code>string</code> presented in the combo box could be "<code>Vowels</code>", or "<code>Voyelles</code>" depending on the language, the value is the constant "<code>Vowels</code>".</p> <h2>Points of Interest</h2> <p>Combo boxes have a <code>DataSource</code> field, so you can use many different sources to populate the box. They also have separate fields for identifying the option chosen. You can use the <code>SelectedIndex</code>, as well as the <code>SelectedText</code> or <code>SelectedValue</code>. You determine what each represents by modifying the <code>DisplayMember</code> or <code>ValueMember</code> field.</p> <p>List boxes are very similar having the same <code>DataSource</code>, <code>DisplayMember</code>, and <code>ValueMember</code>. You can also change each of them programmatically.</p> <p>This code is from the program <a title="Hoot" href="/hoot/" target="_blank">Hoot</a>, a word game study tool I created for Scrabble and Words with Friends players.</p><div class="item_footer"><p><small><a href="https://tylerhosting.com/b2e/dbell.php/managing-localization-in-combo-boxes">Original post</a> blogged on <a href="http://www.tylerhosting.com/b2e/">Switched Keys</a>.</small></p></div>
Deprecated: Creation of dynamic property autolinks_plugin::$setting_nofollow_auto is deprecated in /home4/tylering/public_html/b2e/plugins/_autolinks.plugin.php on line 439

Deprecated: Creation of dynamic property autolinks_plugin::$setting_autolink_defs_coll_db is deprecated in /home4/tylering/public_html/b2e/plugins/_autolinks.plugin.php on line 442

Deprecated: Creation of dynamic property autolinks_plugin::$setting_autolink_urls is deprecated in /home4/tylering/public_html/b2e/plugins/_autolinks.plugin.php on line 443

Deprecated: Creation of dynamic property autolinks_plugin::$setting_autolink_emails is deprecated in /home4/tylering/public_html/b2e/plugins/_autolinks.plugin.php on line 444

Deprecated: Creation of dynamic property autolinks_plugin::$setting_autolink_username is deprecated in /home4/tylering/public_html/b2e/plugins/_autolinks.plugin.php on line 445

Deprecated: Creation of dynamic property autolinks_plugin::$setting_autolink_tag is deprecated in /home4/tylering/public_html/b2e/plugins/_autolinks.plugin.php on line 446

Deprecated: Creation of dynamic property PluginSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Deprecated: Creation of dynamic property PluginSettings::$plugin_ID is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_pluginsettings.class.php on line 36

Deprecated: Creation of dynamic property PluginSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Deprecated: Creation of dynamic property PluginSettings::$plugin_ID is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_pluginsettings.class.php on line 36

Deprecated: Creation of dynamic property autolinks_plugin::$replacement_link_array is deprecated in /home4/tylering/public_html/b2e/plugins/_autolinks.plugin.php on line 341

Deprecated: Creation of dynamic property videoplug_plugin::$video_width is deprecated in /home4/tylering/public_html/b2e/plugins/videoplug_plugin/_videoplug.plugin.php on line 152

Deprecated: Creation of dynamic property videoplug_plugin::$video_height is deprecated in /home4/tylering/public_html/b2e/plugins/videoplug_plugin/_videoplug.plugin.php on line 153

Deprecated: Creation of dynamic property PluginSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Deprecated: Creation of dynamic property PluginSettings::$plugin_ID is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_pluginsettings.class.php on line 36

Deprecated: Creation of dynamic property PluginSettings::$count_col_key_names is deprecated in /home4/tylering/public_html/b2e/inc/settings/model/_abstractsettings.class.php on line 121

Deprecated: Creation of dynamic property PluginSettings::$plugin_ID is deprecated in /home4/tylering/public_html/b2e/inc/plugins/model/_pluginsettings.class.php on line 36

Deprecated: Creation of dynamic property auto_p_plugin::$use_auto_br is deprecated in /home4/tylering/public_html/b2e/plugins/_auto_p.plugin.php on line 126

Deprecated: Creation of dynamic property auto_p_plugin::$add_p_in_block is deprecated in /home4/tylering/public_html/b2e/plugins/_auto_p.plugin.php on line 127

Deprecated: Creation of dynamic property auto_p_plugin::$skip_tags is deprecated in /home4/tylering/public_html/b2e/plugins/_auto_p.plugin.php on line 128

Deprecated: Creation of dynamic property nofollow_plugin::$setting_rel_options is deprecated in /home4/tylering/public_html/b2e/plugins/_nofollow.plugin.php on line 159

Deprecated: Creation of dynamic property nofollow_plugin::$setting_target_options is deprecated in /home4/tylering/public_html/b2e/plugins/_nofollow.plugin.php on line 172

Introduction

This example combines the use of combo boxes, a separate DataSource, and localized strings for alternate cultures.

Background

Using a combo box, programmers can use a selected item as a variable or parameter within a single method. In other cases, the combo box is a collection of options, each of which executes a different method. The combo box can be populated within the design, or assigned using a DataSource. Even a simple string array can be used for that. Processing the selection from the combo box when executing a different method for each combo box entry can be done using the index of the selected item.

string[] special = { "Select", "Vowels", "DoubleI", 
"DoubleU", "NoVowels", "Consonants", "QNotU", 
    "Palins", "HighFives", "HighFours", "NoHooks"};

cboSearch.DataSource = special;

switch (cboSearch.SelectedIndex) {

case 1: btnVowelHeavy_Click(sender, e); break;
        
... 

case 5: btnConsonantDumps_Click(sender, e); break;

...
}

An Alternate

When using the combo box selected index the routine may have to be modified each time a new item is added or items are moved around. If we add an item to the middle of the list, we have to figure out what the item number will be and then change the select statement. Case 2 may be the new one, so the original case 2 has to be changed to case 3, case 3 to case 4, etc.

To avoid that, it is possible to use the selected item's content. Using the actual string in the collection is often a clearer way to code.

switch(cboSearch.SelectedText) {
    case "Vowels": ...

Thus, case 1 would be replaced with case "Vowels". Additions to the collection will not require any reordering.

The Challenge

This works well until you have to support localization, that is, present different collections of strings based on the language selected. The string used in a switch statement must be a constant, so you can't use:

switch (cboSearch.SelectedText) {
    case rm.GetString("Vowels"): ...

We could go back to using indexes, but we want to avoid going back to that. This is where the CultureCombo comes in handy. This simple class and the supporting method uses the characteristics of a combo box to create localized strings, while keeping the ability to process the selection using string identification.

class CultureCombo
{
    public string name {get; set;}
    public string display {get; set;}
}

Next, you would incorporate the method that processes the array. Using this code, you can then apply that to the combo box.

private List<CultureCombo> comboList(string[] termList)
{
    List<CultureCombo> options = new List<CultureCombo>();
    foreach (string word in termList)
        options.Add(new CultureCombo { name = word, display = rm.GetString(word) });
    return options;         
}

The code assumes you have created a ResourceManager called rm. Replace rm above with whatever variable you used for the ResourceManager. In my code, it is represented with the code.

Assembly myAssembly = typeof(Utilities).Assembly;
ResourceManager rm = new ResourceManager("Hoot.Resources.Strings", myAssembly)

Implementation

The first step to using this in a program is to create an array of string IDs, the string used to access the culture's translation. If you have incorporated localized strings, you would already have these. In my example:

string[] special = { "Select", "Vowels", 
"DoubleI", "DoubleU", "NoVowels", "Consonants",
                "QNotU", "Palins", 
                "HighFives", "HighFours", "NoHooks"};

Next, use the method to populate the combo box.

searchOptions = comboList(special);
cboSearch.ValueMember = "name";
cboSearch.DisplayMember = "display";
cboSearch.DataSource = searchOptions;

Finally, find the item in the list by looking at the value (or "name") of the combo box item:

switch (cboSearch.SelectedValue.ToString())
{
    case "Vowels":
        btnVowelHeavy_Click(sender, e);
        break;
    case "Consonants":
        btnConsonantDumps_Click(sender, e);
        break;
..
}

While the string presented in the combo box could be "Vowels", or "Voyelles" depending on the language, the value is the constant "Vowels".

Points of Interest

Combo boxes have a DataSource field, so you can use many different sources to populate the box. They also have separate fields for identifying the option chosen. You can use the SelectedIndex, as well as the SelectedText or SelectedValue. You determine what each represents by modifying the DisplayMember or ValueMember field.

List boxes are very similar having the same DataSource, DisplayMember, and ValueMember. You can also change each of them programmatically.

This code is from the program Hoot, a word game study tool I created for Scrabble and Words with Friends players.

]]>
https://tylerhosting.com/b2e/dbell.php/managing-localization-in-combo-boxes#comments https://tylerhosting.com/b2e/dbell.php?tempskin=_rss2&disp=comments&p=377

Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 932

Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 933

Deprecated: Creation of dynamic property Hit::$is_lynx is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 571

Deprecated: Creation of dynamic property Hit::$is_firefox is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 572

Deprecated: Creation of dynamic property Hit::$is_gecko is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 573

Deprecated: Creation of dynamic property Hit::$is_IE is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 574

Deprecated: Creation of dynamic property Hit::$is_winIE is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 575

Deprecated: Creation of dynamic property Hit::$is_macIE is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 576

Deprecated: Creation of dynamic property Hit::$is_chrome is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 577

Deprecated: Creation of dynamic property Hit::$is_safari is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 578

Deprecated: Creation of dynamic property Hit::$is_opera is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 579

Deprecated: Creation of dynamic property Hit::$is_NS4 is deprecated in /home4/tylering/public_html/b2e/inc/sessions/model/_hit.class.php on line 580