ggeorgiou01
Programmer
Hi all,
I have a windows application and a couple of text entry textboxes, which once filled in, and the button has been clicked, will enter a row into a datagrid.... this works fine (see code)
if (this.CustomerInfoUc.OrderLinesDg.Rows.Count == 0)
{
DataTable dt = new DataTable("test");
DataColumn dc = new DataColumn();
DataRow dr;
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "Line";
dc.AutoIncrement = true;
dc.AutoIncrementSeed = 1;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Code";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Description";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "ExpCode";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "Qty";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Unit";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Price";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Total";
dt.Columns.Add(dc);
dr = dt.NewRow();
dr["Code"] = CodeTb.Text;
dr["Description"] = DescriptionTb.Text;
dr["ExpCode"] = ExpCodeTb.Text;
dr["Qty"] = QtyTb.Text;
dr["Unit"] = UnitTb.Text;
dr["Price"] = PriceTb.Text;
dr["Total"] = TotalPriceTb.Text;
dt.Rows.Add(dr);
this.CustomerInfoUc.OrderLinesDg.DataSource = dt;
StatusLb.Text = "Order line added";
ClearDataGridTextFields();
}
else
{
}
But when i enter some more data into my textboxes and click the button, instead of adding a new row to the datagrid, it overwrites the first row....
How do i go about adding a row, beneath my already added row ?
I have a windows application and a couple of text entry textboxes, which once filled in, and the button has been clicked, will enter a row into a datagrid.... this works fine (see code)
if (this.CustomerInfoUc.OrderLinesDg.Rows.Count == 0)
{
DataTable dt = new DataTable("test");
DataColumn dc = new DataColumn();
DataRow dr;
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "Line";
dc.AutoIncrement = true;
dc.AutoIncrementSeed = 1;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Code";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Description";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "ExpCode";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "Qty";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Unit";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Price";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Total";
dt.Columns.Add(dc);
dr = dt.NewRow();
dr["Code"] = CodeTb.Text;
dr["Description"] = DescriptionTb.Text;
dr["ExpCode"] = ExpCodeTb.Text;
dr["Qty"] = QtyTb.Text;
dr["Unit"] = UnitTb.Text;
dr["Price"] = PriceTb.Text;
dr["Total"] = TotalPriceTb.Text;
dt.Rows.Add(dr);
this.CustomerInfoUc.OrderLinesDg.DataSource = dt;
StatusLb.Text = "Order line added";
ClearDataGridTextFields();
}
else
{
}
But when i enter some more data into my textboxes and click the button, instead of adding a new row to the datagrid, it overwrites the first row....
How do i go about adding a row, beneath my already added row ?