I need help adding rows to datagridwiev using list. I have a class
public class GridObject
{
public string Worker
{
get;
set;
}
[DisplayName("Item name")]
public string ItemName
{ get; set; }
public int Price { get; set; }
public int Quantity { get; set; }
}
And i am making win form app that sould display slod items in datagridview. By now i made it do it like this
private void btnCash_Click(object sender, EventArgs e)
{
dt = new System.Data.DataTable();
using (SqlConnection con = Helper.ConnectionToDatabase)
{
SqlDataAdapter da = new SqlDataAdapter(string.Format(Resources.ViewCommand, tbUser.Text, ItemList.SelectedValue), con);
da.Fill(dt);
//dataDaily.Rows.Clear();
foreach (DataRow item in dt.Rows)
{
int n = dataDaily.Rows.Add();
dataDaily.Rows[n].Cells[0].Value = item[0].ToString();
dataDaily.Rows[n].Cells[1].Value = item[1].ToString();
dataDaily.Rows[n].Cells[2].Value = item[2].ToString();
}
}
}
It works but I wanted to add a new column(quantity) that is not in database and that counts same itmes sold by one user(worker in my case). I tought doing it with list buy i don't know how to fill the list and than display it in datagridview