try this, modify it according to your need
public class SearchItem
{
public string Item_Name { get; set; }
public string Category { get; set; }
public double Price { get; set; }
public double Quantity { get; set; }
public double Total { get; set; }
}
private void btnSearch_Click(object sender, EventArgs e)
{
string search = txtkeyword.Text.Trim();
double quantity;
if (!double.TryParse(txtQty.Text.Trim(), out quantity))
{
MessageBox.Show("Please enter a valid quantity");
return;
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string item_Name = row.Cells[0].Value.ToString();
if (search == item_Name)
{
SearchItem item = new SearchItem()
{
Item_Name = item_Name,
Category = row.Cells[1].Value.ToString(),
Quantity = quantity,
Price = Convert.ToInt32(row.Cells[2].Value.ToString())
};
item.Total = item.Quantity * item.Price;
dataGridView2.Rows.Add(item.Item_Name, item.Category, item.Quantity, item.Price, item.Total);
break;
}
}
}