我制作了一个显示所有非十进制单元格的消息框。
我希望它将所有消息框结果显示为一个。
public void Validate_Month(DataGridView dataGridView, int month, int select)
{
decimal num;
if (dataGridView.ColumnCount > 3)
{
for (int h = select; h <= month; h++)
{
for (int i = 0; i < dataGridView.RowCount; i++)
{
if (!Decimal.TryParse(dataGridView[h, i].Value.ToString(), out num))
{
if (dataGridView[h, i].Value.ToString() == null || dataGridView[h, i].Value.ToString() == "")
{
}
else
{
MessageBox.Show("Row not decimal:" + " [ " + dataGridView[h, i].Value.ToString() + "] in column " + dataGridView.Columns[h].Name);
}
}
}
}
}
}
}
答案 0 :(得分:0)
您可以尝试使用StringBuilder
保存您的信息。
public void Validate_Month(DataGridView dataGridView, int month, int select)
{
decimal num;
StringBuilder sb =new StringBuilder();
if (dataGridView.ColumnCount > 3)
{
for (int h = select; h <= month; h++)
{
for (int i = 0; i < dataGridView.RowCount; i++)
{
if (!Decimal.TryParse(dataGridView[h, i].Value.ToString(), out num))
{
if (dataGridView[h, i].Value.ToString() == null || dataGridView[h, i].Value.ToString() == "")
{
}
else
{
sb.AppendLine("Row not decimal:" + " [ " + dataGridView[h, i].Value.ToString() + "] in column " + dataGridView.Columns[h].Name);
}
}
}
}
}
MessageBox.Show(sb.ToString());
}