遺伝子交差のパネットの方形計算の結果を含む2次元配列の内容を循環しています。ユーザーが一意のインスタンスをすぐに確認できるように、結果を要約する必要があります。結果をテキストボックスに入れることでこれを達成できますが、ListBoxを使用してデータを表示しようとすると、情報の一部が失われます。つまり、AaBBCcタイプのデータを特性に直接関連するものに変換します。ユーザーが最初に選択したもの。
これは、操作のコードのメインブロックです。
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() + "%.");
}
テキストボックスにデータを追加するために、このコードを使用します。これは完全に機能します。
txtReport.AppendText(DecodeGenome(strCombination) + " appears " + intUniqueCount.ToString() + " times or " + decPercentage.ToString() + "%."+ Environment.NewLine);
結果を与える: 特性1ヘット、特性3は16回または25%出現します。
結果をリストボックスに追加する場合、これは機能します。
lstCrossResult.Items.Add(strCombination + " appears " + intUniqueCount.ToString() + " times or " + decPercentage.ToString() + "%.");
結果を与える: AaBBCcは16回または25%出現します。
しかし、strCombinationの内容はAaBBCcであり、「Trait 1 Het。、Trait 3」に変換する必要があります。これは、次のコードで実現します。
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 <= 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 > 0)
{
txtReport.AppendText(GetDescription(strPair.Substring(0, 1)) + " Het.,");
}
else
{
txtReport.AppendText(GetDescription(strPair.Substring(0, 1)));
}
}
}
else
{
if (!Char.IsUpper(chSecondLetter))
{
if (intCounter > 0)
{
txtReport.AppendText(GetDescription(strPair.Substring(0, 1)) + ",");
}
else
{
txtReport.AppendText(GetDescription(strPair.Substring(0, 1)));
}
}
}
}
return strTranslation;
}
テキストボックスに表示しても問題ありませんが、アイテムとしてリストボックスに入れようとすると、nullになります。代わりに: 「特性1ヘット、特性3は16回または25%出現します。」 「16回または25%表示されます 。」
結果をArrayListに追加し、すべてが処理された後にリストボックスにデータを入力しようとしましたが、結果は同じです。
リストボックスが翻訳されたAaBBCc情報を受け入れない理由に関する手がかりをいただければ幸いです。