S
Sam Dahan
When I use the Form wizard to add a DataSet, DataTable and connect a
DataGrid to the DataTable, the expression is never evaluated in the
calculated column. Is this a known bug in VS.NET 2003? Is there
aworkaround more convenient than the one I give below?
Thanks for any answers...
Here is the code generated by the wizard (some replaced by ellipsis
for clarity):
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
..
this.dataGrid1.DataSource = this.dataTable1;
..
//
// dataSet1
//
..
this.dataSet1.Tables.AddRange(new System.Data.DataTable[]
{this.dataTable1});
//
// dataTable1
//
this.dataTable1.Columns.AddRange(new System.Data.DataColumn[] {
this.dataColumn1,
this.dataColumn2,
this.dataColumn3});
..
//
// dataColumn1
//
this.dataColumn1.ColumnName = "a";
this.dataColumn1.DataType = typeof(System.Decimal);
//
// dataColumn2
//
this.dataColumn2.ColumnName = "b";
this.dataColumn2.DataType = typeof(System.Decimal);
//
// dataColumn3
//
this.dataColumn3.ColumnName = "ab";
this.dataColumn3.DataType = typeof(System.Decimal);
this.dataColumn3.Expression = "a*b";
this.dataColumn3.ReadOnly = true;
...
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit();
this.ResumeLayout(false);
When I run this and type some value in column a nd b, the value in
column ab is still (null).
However, when I comment out the calls to BeginInit() and EndInit() for
DataTable1, the expression is evaluated as soon as I navigate away
from the column ab, as expected.
------------------------------------
Just for kicks, the following code (implemented in a button click
handler, for example) will generate a datatable that will evaluate the
expression w/o problems:
DataColumn dc1 = new System.Data.DataColumn("A",
typeof(System.Decimal));
DataColumn dc2 = new System.Data.DataColumn("B",
typeof(System.Decimal));
DataColumn dc3 = new System.Data.DataColumn("AB",
typeof(System.Decimal), "A*B");
dc3.ReadOnly = true;
DataTable dt = new System.Data.DataTable("Multiply");
dt.Columns.AddRange(new DataColumn[]{dc1, dc2, dc3});
this.dataGrid1.DataSource = dt;
DataGrid to the DataTable, the expression is never evaluated in the
calculated column. Is this a known bug in VS.NET 2003? Is there
aworkaround more convenient than the one I give below?
Thanks for any answers...
Here is the code generated by the wizard (some replaced by ellipsis
for clarity):
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
..
this.dataGrid1.DataSource = this.dataTable1;
..
//
// dataSet1
//
..
this.dataSet1.Tables.AddRange(new System.Data.DataTable[]
{this.dataTable1});
//
// dataTable1
//
this.dataTable1.Columns.AddRange(new System.Data.DataColumn[] {
this.dataColumn1,
this.dataColumn2,
this.dataColumn3});
..
//
// dataColumn1
//
this.dataColumn1.ColumnName = "a";
this.dataColumn1.DataType = typeof(System.Decimal);
//
// dataColumn2
//
this.dataColumn2.ColumnName = "b";
this.dataColumn2.DataType = typeof(System.Decimal);
//
// dataColumn3
//
this.dataColumn3.ColumnName = "ab";
this.dataColumn3.DataType = typeof(System.Decimal);
this.dataColumn3.Expression = "a*b";
this.dataColumn3.ReadOnly = true;
...
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit();
this.ResumeLayout(false);
When I run this and type some value in column a nd b, the value in
column ab is still (null).
However, when I comment out the calls to BeginInit() and EndInit() for
DataTable1, the expression is evaluated as soon as I navigate away
from the column ab, as expected.
------------------------------------
Just for kicks, the following code (implemented in a button click
handler, for example) will generate a datatable that will evaluate the
expression w/o problems:
DataColumn dc1 = new System.Data.DataColumn("A",
typeof(System.Decimal));
DataColumn dc2 = new System.Data.DataColumn("B",
typeof(System.Decimal));
DataColumn dc3 = new System.Data.DataColumn("AB",
typeof(System.Decimal), "A*B");
dc3.ReadOnly = true;
DataTable dt = new System.Data.DataTable("Multiply");
dt.Columns.AddRange(new DataColumn[]{dc1, dc2, dc3});
this.dataGrid1.DataSource = dt;