|
 |
|
เกิดปัญหา การเช็คใน loop ครับ ทำยังไงไม่ให้มันซ้ำกัน |
|
 |
|
|
 |
 |
|
รับ id มาจาก datagridview
เพื่อ add เข้า listview
Code (C#)
foreach(DataGridViewRow d in datagridwatercan.SelectedRows)ๅ
{
int datag2 = listwatercan.Rows.Count;
if (datag2 == 1) //ถ้าใน listview ยังไม่มีข้อมูลใดๆให้ เพิ่มเลย
{
listwatercan.Rows.Add(d.Cells[0].Value, d.Cells[1].Value, d.Cells[2].Value, d.Cells[3].Value, d.Cells[4].Value, d.Cells[5].Value);
}
else // ถ้ามี่ขอมูลอยุ่แล้วให้เช็คเง่อนไข
{
for (int i = 0; i <= datag2; i++)
{
string chkloop = listwatercan.Rows[i].Cells["can_id"].Value.ToString();//ข้อมูลที่รับมาจาก dagatridview
if (chkloop == d.Cells[0].Value.ToString()) // เทียบข้อมูลจาก datagridview กับ listbox อันเดิม
{
MessageBox.Show("น้ำอัดลมถูกเลือกแล้วคะ");
return; }
else
{
listwatercan.Rows.Add(d.Cells[0].Value, d.Cells[1].Value, d.Cells[2].Value, d.Cells[3].Value, d.Cells[4].Value, d.Cells[5].Value);
break;
}
}
}
ปัญหาอยุ่ตรงที่ ค่าที่เช็คลงมั่ว ซ้ำกันหมดเลยครับ
Tag : .NET, Ms SQL Server 2008, C#, VS 2010 (.NET 4.x)

|
|
 |
 |
 |
 |
Date :
2012-04-26 05:01:04 |
By :
sticko |
View :
1140 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก็บลง DataTable หรืออื่น ๆ ก่อนแล้วค่อยตรวจสอบพวก Duplicate ได้หรือเปล่าครับ มันมีพวก Method เกี่ยวกับ Exists อยู่ครับ
|
 |
 |
 |
 |
Date :
2012-04-26 13:04:05 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|