Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I stop [ ] appearing when inserting the value of a KeyValuePair<string, string> into a list control?
    primarykey
    data
    text
    <p>As it stands I'm using a Dictionary to store answers to a question in the following format:-</p> <pre><code>Destination: A1 - Warehouse A2 - Front Office A3 - Developer Office A4 - Admin Office B1 - Support </code></pre> <p>A1, A2 etc are unique identifiers used to select questions elsewhere and the answer is tagged on at the end, the dictionary stores ID and the Answer.</p> <p>This part all works fine. The problem is when inserting the data into a list box/combo box. At the moment I'm using the method below:</p> <pre><code>foreach (KeyValuePair&lt;string, string&gt; oTemp in aoObjectArray) { if (listControl is ComboBox) { ((ComboBox)listControl).Items.Add(string.Format("{0} - {1}", oTemp.Key, oTemp.Value)); } else if (listControl is ListBox) { ((ListBox)listControl).Items.Add(string.Format("{0} - {1}", oTemp.Key, oTemp.Value)); } } </code></pre> <p>This inserts the correct data into the list/combo box but in the following format:</p> <pre><code>Destination: [A1: Warehouse] [A2: Front Office] [A3: Developer Office] [A4: Admin Office] [B1: Support] </code></pre> <p>I've tried a number of other methods to get rid of the squared brackets. Interestingly if I just do</p> <pre><code>((ComboBox)listControl).Items.Add(string.Format(oTemp.Value)); </code></pre> <p>I still get the data out in the [A1: Warehouse] format. How can I get rid of the squared brackets?</p> <p>EDIT: Been asked to add more code. Here is the full add to list control method:</p> <pre><code>public static void AddDictionaryToListControl(ListControl listControl, Dictionary&lt;string, string&gt; aoObjectArray) { foreach (KeyValuePair&lt;string, string&gt; oTemp in aoObjectArray) { if (listControl is ComboBox) { ((ComboBox)listControl).Items.Add(string.Format(oTemp.Value)); } else if (listControl is ListBox) { ((ListBox)listControl).Items.Add(string.Format(oTemp.Value)); } } } </code></pre> <p>This method is called from:</p> <pre><code> public ComboBox AddQuestionsComboBox(Dictionary&lt;string, string&gt; Items, string Label, string Key, int Order, bool Mandatory) { ComboBox output; output = AddControl&lt;ComboBox&gt;(Label, Key, Order); FormsTools.AddDictionaryToListControl(output, Items); AddTagField(output, Tags.Mandatory, Mandatory); return output; } </code></pre> <p>Which is called using the following line:</p> <pre><code>AddQuestionsComboBox(question.PickList, question.PromptTitle, question.FieldTag, i, offquest.Mandatory); </code></pre> <p>Hope that helps.</p> <p>EDIT: I've tried all the suggestions below and still no improvement - I've checked and rechecked the code and all methods that relate to it for some additional formatting I've missed and found nothing that could cause the formatting to be set correctly at one stage and then binned by the time it gets on screen.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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