J
Jeff Johnson
Registered User said:the OP's initial problem where setting the Caption property of theprivate void CreateDataTable()
{
DataTable table;
DataColumn column;
table = new DataTable("Customers");
//CustomerID column
column = table.Columns.Add("CustomerID",
System.Type.GetType("System.Int32"));
column.Unique = true;
column = table.Columns.Add();
column.ColumnName = "CustomerName";
column.DataType = System.Type.GetType("System.String");
column.Caption = "Name";
//CreditLimit
column = table.Columns.Add("CreditLimit",
System.Type.GetType("System.Double"));
column.DefaultValue = 0;
// this line does not set the property as expected
column.Caption = "Limit";
// yet this line does set the property as expected
table.Columns[2].Caption = "Limit";
table.Rows.Add(new object[] { 1, "Jonathan", 23.44 });
table.Rows.Add(new object[] { 2, "Bill", 56.87 });
}
Interesting, how the caption is set makes a difference.
I must correct myself. How the column is added to the table appears to
make the difference. When the CustomerName column is added as shown
above, the column's Caption property is set to 'Name' just as
expected.
Versus...?
DataColumn object returned by DataTable.Add(string, type) did not
work.
Oh, I see your comments in the code now.