The DataColumn property caption is of no use

J

Jeff Johnson

Registered User said:
private 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...?
the OP's initial problem where setting the Caption property of the
DataColumn object returned by DataTable.Add(string, type) did not
work.

Oh, I see your comments in the code now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top