[英]Reading data from the DataGridView just reads the last row c#
我已經能夠表明每當工具提示quantity
小於5
為該productcode
與約束,但一旦提示已被證明,它只是閱讀的DataGridView的最后一行,並不是所有的數據更里面。
這是圖片:
從上面的圖像中,您可以看到數量少於5的兩個產品代碼,但是如果從右下角看到,它僅顯示數據的最后一行。
這是我正在使用的代碼:
void CheckQuantity()
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string productCode = row.Cells[0].Value.ToString();
decimal quantity = Convert.ToDecimal(row.Cells[1].Value);
if (quantity < 5)
{
SystemManager.SoundEffect("C:/Windows/Media/Speech Off.wav");
customToolTip1.Show("- Product Code: " + productCode + "\n- Quantity: " + quantity, this, _screen.Right, _screen.Bottom, 5000);
timeLeft = 15;
_timer.Start();
}
else
{
timeLeft = 15;
_timer.Start();
}
}
}
void Timer_Tick(object sender, EventArgs e)
{
timeLeft--;
if (timeLeft == 0)
{
_timer.Stop();
CheckQuantity();
}
}
void Database_Load(object sender, EventArgs e)
{
_timer.Start();
}
void Database_FormClosed(object sender, FormClosedEventArgs e)
{
_timer.Stop();
}
uint timeLeft = 15;
感謝您的回答。
謝謝。
您所期望的結果還不清楚,這是您的意思嗎?
void CheckQuantity()
{
string msg = "";
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string productCode = row.Cells[0].Value.ToString();
decimal quantity = Convert.ToDecimal(row.Cells[1].Value);
if (quantity < 5)
{
msg += "- Product Code: " + productCode + " - Quantity: " + quantity + "\n";
}
}
if (msg != "")
{
SystemManager.SoundEffect("C:/Windows/Media/Speech Off.wav");
customToolTip1.Show(msg, this, _screen.Right, _screen.Bottom, 5000);
}
}
void Timer_Tick(object sender, EventArgs e)
{
_timer.Stop();
CheckQuantity();
}
void Database_Load(object sender, EventArgs e)
{
_timer.Interval = 15 * 1000;
_timer.Start();
}
void Database_FormClosed(object sender, FormClosedEventArgs e)
{
_timer.Stop();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.