The DataColumn property caption is of no use

T

Tony

Hello!

I can't see any use of the property Caption in the DataColumn class because
you can't change the column title by using that property.
Here I have a short code snippet where I change the Caption on the third
added column to Limit but if I look at the
DataTable its still show the column title as CreditLimit so setting the
Caption has no effect.

I hope someone can correct me if I'm wrong about this caption property on
the DataColum class.

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;

//CustomerName column
column = table.Columns.Add("CustomerName",
System.Type.GetType("System.String"));
column.Caption = "Name";

//CreditLimit
column = table.Columns.Add("CreditLimit",
System.Type.GetType("System.Double"));
column.DefaultValue = 0;
column.Caption = "Limit";

table.Rows.Add(new object[] { 1, "Jonathan", 23.44 });
table.Rows.Add(new object[] { 2, "Bill", 56.87 });
}

//Tony
 
J

Jeff Johnson

I can't see any use of the property Caption in the DataColumn class
because you can't change the column title by using that property.
Here I have a short code snippet where I change the Caption on the third
added column to Limit but if I look at the
DataTable its still show the column title as CreditLimit so setting the
Caption has no effect.

I hope someone can correct me if I'm wrong about this caption property on
the DataColum class.

Just a guess, but this property is probably used by other code to set a
caption when autogenerating a form or report based on the DataTable,
assuming you want to use something other than the underlying column's name.
MS Access has had this capability for years. It's PURELY for display. MSDN
says this:

You can use the Caption property to display a descriptive or friendly name
for a DataColumn.
 
T

Tony

Jeff Johnson said:
Just a guess, but this property is probably used by other code to set a
caption when autogenerating a form or report based on the DataTable,
assuming you want to use something other than the underlying column's
name. MS Access has had this capability for years. It's PURELY for
display. MSDN says this:

You can use the Caption property to display a descriptive or friendly name
for a DataColumn.

It has no affect if you use it as the MSDN says like
You can use the Caption property to display a descriptive or friendly name
for a DataColumn.
If will has no effect ?
So this caption is of no use.

//Tony

//Tony
 
J

Jeff Johnson

Tony said:
It has no affect if you use it as the MSDN says like
You can use the Caption property to display a descriptive or friendly name
for a DataColumn.
If will has no effect ?
So this caption is of no use.

How can I say it clearer? It is of use to OTHER things. If you don't use
those other things then it's meaningless FOR YOU, but not necessarily for
other people.
 
T

Tony

Jeff Johnson said:
How can I say it clearer? It is of use to OTHER things. If you don't use
those other things then it's meaningless FOR YOU, but not necessarily for
other people.

What I want to say is that the manual say the following
"You can use the Caption property to display a descriptive or friendly name
for a DataColumn"
So this would mean that the header for the column in a DataGridView or
DataGrid would have the name from the Caption but that is not what would
happen."

So the manual about this Caption property is completely wrong no matter what
you say.

//Tony
 
J

Jeff Johnson

What I want to say is that the manual say the following
"You can use the Caption property to display a descriptive or friendly
name for a DataColumn"
So this would mean that the header for the column in a DataGridView or
DataGrid would have the name from the Caption but that is not what would
happen."

So the manual about this Caption property is completely wrong no matter
what you say.

Okay, a quick Web search seems to indicate that this property is not used by
any built-in Microsoft controls. However, its purpose remains the same: it's
there for you to STORE a string to be used in place of the column name.
However, it seems like it's UP TO YOU to actually use this name.

I guess it's like the Tag property. Will you suggest the Tag property is
useless simply because nothing built-in to the Framework automatically uses
it?

Also, I argue that MSDN is RIGHT, but not CLEAR. (Reminds me of the old joke
about the guy in the balloon....) I says "YOU can use the Caption
property..." and it really means it: it's there for YOU, and only you,
apparently.
 
A

Arne Vajhøj

What I want to say is that the manual say the following
"You can use the Caption property to display a descriptive or friendly
name for a DataColumn"
So this would mean that the header for the column in a DataGridView or
DataGrid would have the name from the Caption but that is not what would
happen."

So the manual about this Caption property is completely wrong no matter
what you say.

Nothing prevents you from writing the TonyGrid class that
does display that property.

Maybe there is a JeffGrid that does that.

The fact that DataGridView and DataGrid does not use it is not the
same that nothing will ever use it.

Arne
 
J

Jeff Johnson

Maybe there is a JeffGrid that does that.

I've never even considered writing a grid. Lots o' work! However, I did
write a "canvas" control once. It was basically a stripped-down version of
the Windows Workflow designer. Quite a bit of work went into displaying the
boxes that could be placed on the canvas, I can tell you! And the piece I
was most proud of was the "thumbnail navigator," which you use to quickly
move to parts of the canvas that aren't visible.

Writing controls is kind of cool, if you're willing to put in the time. I
applaud those who do.
 
P

Phil Hunt

The fact that DataGridView and DataGrid does not use it is not the
same that nothing will ever use it.

Arne

I am no expert with the grid. But if the DataGrid itself does not use it,
how can it make claim that the field will be used to display as alternate.
It is just a all-purpose property like a Tag. No ?
 
J

Jeff Johnson

I am no expert with the grid. But if the DataGrid itself does not use it,
how can it make claim that the field will be used to display as alternate.
It is just a all-purpose property like a Tag. No ?

The trick is in the wording. The MSDN description never says that anything
WILL use this property, just that it CAN be used for such a purpose. I agree
that it SUGGESTS that something will use it, and since Microsoft shouldn't
be making claims about other people's software, that also SUGGESTS that
something Microsoft wrote will be the consumer, but that isn't the case.

My guess: they intended to use it and then scrapped the idea.
 
J

Jeff Johnson

Peter Duniho said:
[...]
I am no expert with the grid. But if the DataGrid itself does not use
it,
how can it make claim that the field will be used to display as
alternate.
It is just a all-purpose property like a Tag. No ?

The trick is in the wording. The MSDN description never says that
anything
WILL use this property, just that it CAN be used for such a purpose.
[...]

More to the point of Phil's question: when he writes "if the DataGrid
itself does not use it, how can it make claim.", he's falling into the
trap of making a bogus assumption about what's claiming what.

"It" (which in that statement must be the DataGrid type) does _not_ make
any such claim. The documentation describing the Caption property isn't
part of DataGrid at all. It's part of the DataColumn type.

Actually, I think he was being fast and loose with his pronouns. My take:

"But if the DataGrid itself does not use it [the Caption property of the
DataColumn], how can it [the DataColumn] make claim that the field [the
Caption property (not "field")] will be used to display as alternate."

Isn't English fun?
 
P

Phil Hunt

Actually, I think he was being fast and loose with his pronouns. My take:
"But if the DataGrid itself does not use it [the Caption property of the
DataColumn], how can it [the DataColumn] make claim that the field [the
Caption property (not "field")] will be used to display as alternate."

Isn't English fun?

I never read the documentation. But can someone show me a place in the
framework that uses the property to display the so called 'caption' ? Sure
you or I can use it to display, I can also use it for something else too.
 
J

Jeff Johnson

Actually, I think he was being fast and loose with his pronouns. My take:

"But if the DataGrid itself does not use it [the Caption property of the
DataColumn], how can it [the DataColumn] make claim that the field [the
Caption property (not "field")] will be used to display as alternate."

Isn't English fun?

I never read the documentation. But can someone show me a place in the
framework that uses the property to display the so called 'caption' ? Sure
you or I can use it to display, I can also use it for something else too.

That's what we're saying: there doesn't seem to be any place that the
framework uses it. But we're also saying that the documentation doesn't
ACTUALLY SAY that some other part of the framework WILL use this property;
most people simply INFER that. (I certainly did, but that was mainly due to
my experience with Access. A more thorough search revealed that this
property is just...there.)
 
R

Registered User

Hello!

I can't see any use of the property Caption in the DataColumn class because
you can't change the column title by using that property.
Here I have a short code snippet where I change the Caption on the third
added column to Limit but if I look at the
DataTable its still show the column title as CreditLimit so setting the
Caption has no effect.

I hope someone can correct me if I'm wrong about this caption property on
the DataColum class.
OK you're wrong ;)
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;

//CustomerName column
column = table.Columns.Add("CustomerName",
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.

regards
A.G.
 
R

Registered User

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.

regards
A.G.
 
A

Arne Vajhøj

I've never even considered writing a grid. Lots o' work! However, I did
write a "canvas" control once. It was basically a stripped-down version of
the Windows Workflow designer. Quite a bit of work went into displaying the
boxes that could be placed on the canvas, I can tell you! And the piece I
was most proud of was the "thumbnail navigator," which you use to quickly
move to parts of the canvas that aren't visible.

Writing controls is kind of cool, if you're willing to put in the time. I
applaud those who do.

Writing a heavyweight control is probably a lot of work.

But it does not even need to be such a thing.

One could also use it for dumping the DataSet to XML.

That is not a big task to write code for.

Arne
 
A

Arne Vajhøj

I am no expert with the grid. But if the DataGrid itself does not use it,
how can it make claim that the field will be used to display as alternate.
It is just a all-purpose property like a Tag. No ?

The docs for DataColumn states:

"You can use the Caption property to display a descriptive or friendly
name for a DataColumn."

"can use" does not imply "will use".

Arne
 
A

Arne Vajhøj

Actually, I think he was being fast and loose with his pronouns. My take:

"But if the DataGrid itself does not use it [the Caption property of the
DataColumn], how can it [the DataColumn] make claim that the field [the
Caption property (not "field")] will be used to display as alternate."

Isn't English fun?

I never read the documentation. But can someone show me a place in the
framework that uses the property to display the so called 'caption' ? Sure
you or I can use it to display, I can also use it for something else too.

A little search showed that it is used for schema generation.

Demo:

using System;
using System.Data;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
DataTable dt = new DataTable("T");
dt.Columns.Add(new DataColumn("C1", typeof(int)));
dt.Columns.Add(new DataColumn("C2", typeof(string)));
dt.WriteXmlSchema(Console.Out);
dt.Columns["C1"].Caption = "This is C1";
dt.Columns["C2"].Caption = "This is C2";
dt.WriteXmlSchema(Console.Out);
Console.ReadKey();
}
}
}

Arne
 
J

Jeff Johnson

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...?
 
R

Registered User

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.

regards
A.G.
 

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