Data lost while adding string to listbox
<p>I am cycling through the contents of a two-dimensional array containing the result of a Punnett Square calculation for gene crosses.  I need to summarize the result so that the user can readily see the unique instances.  I can accomplish this by putting the result into a text box, but when I try and use a ListBox to display the data, part of the information is getting lost, namely a translation of the AaBBCc type data to something that directly relates to the traits that the user initially selected.</p>

<p>This is the main block of code for the operation:</p>

<pre><code>    foreach (string strCombination in arrUniqueCombinations)
    {
        int intUniqueCount = 0;
        decimal decPercentage;
        foreach (string strCrossResult in arrPunnettSQ)
        {
            if (strCrossResult == strCombination)
            {
                intUniqueCount++;
            }
        }
        decPercentage = Convert.ToDecimal((intUniqueCount*100)) / Convert.ToDecimal(intPossibleCombinations);
        txtReport.AppendText(strCombination + " appears " + intUniqueCount.ToString() + " times or " + decPercentage.ToString() + "%."+ Environment.NewLine);

        lstCrossResult.Items.Add(DecodeGenome(strCombination) + " appears " + intUniqueCount.ToString() + " times or " + decPercentage.ToString() + "%.");
    }
</code></pre>

<p>For appending the data to the textbox I use this code and it works perfectly:</p>

<pre><code>txtReport.AppendText(DecodeGenome(strCombination) + " appears " + intUniqueCount.ToString() + " times or " + decPercentage.ToString() + "%."+ Environment.NewLine);
</code></pre>

<p>Giving the result:
<strong>Trait 1 Het.,Trait 3 appears 16 times or 25%.</strong></p>

<p>For adding the result to a list box, this works:</p>

<pre><code>lstCrossResult.Items.Add(strCombination + " appears " + intUniqueCount.ToString() + " times or " + decPercentage.ToString() + "%.");
</code></pre>

<p>Giving the result:
<strong>AaBBCc appears 16 times or 25%.</strong></p>

<p>But the contents of strCombination is AaBBCc and I need it translated to "Trait 1 Het.,Trait 3", which I accomplish with this bit of code:</p>

<pre><code>private string DecodeGenome(string strGenome)
{
    string strTranslation = "";
    int intLength = strGenome.Length;
    int intCounter = intLength / 2;
    string[] arrPairs = new string[intLength / 2];


    //Break out trait pairs and load into array

    for (int i = 1; i &lt;= intLength; i++)
    {
        arrPairs[i / 2] = strGenome.Substring((i-1),2);
        i++;
    }

    foreach (string strPair in arrPairs)
    {
        char chFirstLetter = strPair[0];
        char chSecondLetter = strPair[1];
        intCounter = intCounter - 1;

        if (Char.IsUpper(chFirstLetter))
        {
            if (!Char.IsUpper(chSecondLetter))
            {
                if (intCounter &gt; 0)
                {
                    txtReport.AppendText(GetDescription(strPair.Substring(0, 1)) + " Het.,");
                }
                else
                {
                    txtReport.AppendText(GetDescription(strPair.Substring(0, 1)));
                }
            }
        }
        else
        {
            if (!Char.IsUpper(chSecondLetter))
            {
                if (intCounter &gt; 0)
                {
                    txtReport.AppendText(GetDescription(strPair.Substring(0, 1)) + ",");
                }
                else
                {
                    txtReport.AppendText(GetDescription(strPair.Substring(0, 1)));
                }
            }

        }

    }

    return strTranslation;
}
</code></pre>

<p>That has no problem displaying in a text box, but when I try and put it as an item into a list box it turns it into null.  Instead of:
<strong>"Trait 1 Het.,Trait 3 appears 16 times or 25%."</strong>
I get:
<strong>" appears 16 times or 25%."</strong></p>

<p>I have tried adding the results to an ArrayList, then populating the listbox after everything is processed, but the result is the same.</p>

<p>Any clues as to why the list box is not accepting the translated AaBBCc information would be greatly appreciated.</p>
