ms Visual Studioとcsharp .net4を使用します。
これは、重複をチェックする必要があるコードです
public void CheckForDuplicate()
{
DataGridViewRowCollection coll = ParetoGrid.Rows;
DataGridViewRowCollection colls = ParetoGrid.Rows;
List<string> listParts = new List<string>();
int count = 0;
foreach (DataGridViewRow item in coll)//379
{
foreach (DataGridViewRow items in colls)//143641
{
if (items.Cells[5].Value == item.Cells[5].Value)
{
if (items.Cells[2].Value != item.Cells[2].Value)
{
listParts.Add(items.Cells["Keycode"].Value.ToString());
count++;
dupi = true;
//txtDupe.Text = items.Cells["Keycode"].Value.ToString();
//this.Refresh();
}
}
}
}
MyErrorGrid.DataSource = listParts;
}
これは、ユーザーが保存できるようにする前のチェックです。
private void butSave_Click(object sender, EventArgs e)
{
CheckForDuplicate();
if (dupi == true)
{
txtDupe.Clear();
dupi = false;
}
else
{
SaveMyWorkI();
dupi = false;
}
}
これは、それが見ているデータです:
これで、保存に関係なくロジックに欠陥があるに違いないことがわかりました。私は基本的にpareto1の各セルを検索して、ユーザーが重複を作成したかどうかを確認しています。重複している場合は保存せず、代わりに部品番号などを別のデータグリッドビューに表示します....それが計画です。
誰かがこれを見て教えてくれませんか
1)私のロジックのどこでこれが失敗していますか?また、チェックが正しいかどうかはどうですか?
2)データグリッド ビューへの単純なバインドで結果を表示するのに十分な場合、リストは情報を追加して機能しますか?
3)これが本当に悪い検索方法である場合、誰かが私が達成しようとしていることを反映したコードを提供できます。
今後ともコメントをよろしくお願いいたします。
更新:: 助けてくれてありがとう、私のアルゴリズムは動作するようになりましたが、私の最後の問題は、パレート列に複製された部品番号を表示することであり、代わりに長さを表示します。
public void CheckForDuplicate()
{
DataGridViewRowCollection coll = ParetoGrid.Rows;
DataGridViewRowCollection colls = ParetoGrid.Rows;
List<string> listParts = new List<string>();
int count = 0;
foreach (DataGridViewRow item in coll)//379
{
foreach (DataGridViewRow items in colls)//143641
{
count++;
if ((items.Cells[5].Value != null))
{
if ((items.Cells[5].Value != null) && (items.Cells[5].Value.Equals(item.Cells[5].Value)))
{
if ((items.Cells[2].Value != null) && !(items.Cells[2].Value.Equals(item.Cells[2].Value)))
{
listParts.Add(items.Cells["Keycode"].Value.ToString());
dupi = true;
}
}
}
}
}
MyErrorGrid.DataSource = listParts;
var message = string.Join(Environment.NewLine, listParts);
//MyErrorGrid.DataSource = message;
MessageBox.Show(message);
}
メッセージ ボックスには結果が正しく表示されますが、データグリッドにバインドするときに見逃しているものはありますか?