Sorry as I misunderstood your problem. If you want to add new row to the DataTable object on button click, then you have to define the DataTable object outside the button click event. Otherwise each time it will add only one row only. So please try as below.
Use a private variable to define the DataTable object like this
private DataTable dt;
Then initialize the DataTable object in Form load event like:
dt = new DataTable();
dt.Columns.Add("inventoryName");
dt.Columns.Add("Quantity");
dt.Columns.Add("Total");
Then use your previous code as below:
private void B_Click(object sender, EventArgs e)
{
Button bt = (Button)sender;
int productId = (int)bt.Tag;
AddProductDataContext db = new AddProductDataContext();
decimal Quantity;
decimal.TryParse(txtCalculator.Text, out Quantity);
var results = from inv in db.Inventories
where inv.RecId == productId
select new
{
inventoryName = inv.InventoryName,
Quantity,
Total = Quantity * inv.InventoryPrice
};
foreach (var x in results)
{
DataRow newRow = dt.NewRow();
newRow.SetField("inventoryName", x.inventoryName);
newRow.SetField("Quantity", x.Quantity);
newRow.SetField("Total", x.Total);
dt.Rows.Add(newRow);
}
gridControl1.DataSource = dt;
}
Please let me know.