The concept of your loop is wrong ... you will end up adding a row each time you encounter one where the CardId is not matched. If CardId is 2 and you have a grid with 0,1,2 then you will add a row when you encounter 0, then again when you encounter 1.
If the datagridview is empty (as you say) you won't enter the code within the foreach loop - but this tells you that the CardId definitely isn't in the data! So do the adding of the row outside of that loop. Here's one way of doing that ...
int rowFound = -1;
foreach (DataGridViewRow row in DGViewTWInv.Rows)
{
if (int.Parse(row.Cells[0].Value.ToString()) == CardId)
{
rowFound = row.Index;
break;
}
}
if (rowFound == -1)
this.DGViewTWInv.Rows.Add(CardId, "Other Data");