ggeorgiou01
Programmer
Morning all,
I am encountering an extremly annoying prooblem. Which is doing my head in. Can you guys help ?
I my windows form i am using a datagridview.
Ok so heres what im doing:
__________________________________________________________
On Load, i am binding my columns to the datagrid:
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "#";
dc.ReadOnly = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Code";
dc.MaxLength = 7;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Description";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "Qty";
dc.ReadOnly = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Exp Code";
dc.ReadOnly = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Unit";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Price";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Total";
dc.ReadOnly = true;
dt.Columns.Add(dc);
__________________________________________________________
Then i have a CellValueChanged event which includes the following:
if (OrderLinesDg["Qty", RowNo].Value != DBNull.Value)
{
decimal TotalPrice = Convert.ToDecimal(OrderLinesDg["Qty", RowNo].Value) * Convert.ToDecimal(OrderLinesDg["Price", RowNo].Value);
OrderLinesDg["Total", RowNo].ReadOnly = false;
OrderLinesDg["Total", RowNo].Value = TotalPrice.ToString("F");
OrderLinesDg["Total", RowNo].ReadOnly = true;
}
__________________________________________________________
When i run this code, i get an error message saying the 'Total' cloumn is readonly. Which i cannot understand as i have made the readonly attribute to false. Before i right into the column.
Any help would be much apprciated.
I am encountering an extremly annoying prooblem. Which is doing my head in. Can you guys help ?
I my windows form i am using a datagridview.
Ok so heres what im doing:
__________________________________________________________
On Load, i am binding my columns to the datagrid:
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "#";
dc.ReadOnly = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Code";
dc.MaxLength = 7;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Description";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Int32");
dc.ColumnName = "Qty";
dc.ReadOnly = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Exp Code";
dc.ReadOnly = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.String");
dc.ColumnName = "Unit";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Price";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = Type.GetType("System.Decimal");
dc.ColumnName = "Total";
dc.ReadOnly = true;
dt.Columns.Add(dc);
__________________________________________________________
Then i have a CellValueChanged event which includes the following:
if (OrderLinesDg["Qty", RowNo].Value != DBNull.Value)
{
decimal TotalPrice = Convert.ToDecimal(OrderLinesDg["Qty", RowNo].Value) * Convert.ToDecimal(OrderLinesDg["Price", RowNo].Value);
OrderLinesDg["Total", RowNo].ReadOnly = false;
OrderLinesDg["Total", RowNo].Value = TotalPrice.ToString("F");
OrderLinesDg["Total", RowNo].ReadOnly = true;
}
__________________________________________________________
When i run this code, i get an error message saying the 'Total' cloumn is readonly. Which i cannot understand as i have made the readonly attribute to false. Before i right into the column.
Any help would be much apprciated.