DataColumn.Table property

  • Thread starter Thread starter jpatrick
  • Start date Start date
J

jpatrick

DataTable dataTable = new DataTable();
DataColumn dataColumn = new DataColumn();
// dataColumn.Table is null
dataTable.Columns.Add(dataColumn);
// dataColumn.Table is dataTable

DataColumn Table property is read-only. So how that property is changed? If
it can only be changed internally by the class itself, how does the
DataColumn know it has been added to that table to set the property?
 
I don't know how it's actualy doing it, but one way would be that the
DataTable is calling a method on the DataColumn and passing a reference to
itself which the DataColumn is storing in it's Table property.
 
Yes. I thought about that, but didn't find any method on DataColumn that
would fit.
Yet there's another issue. Actually, the Table's Columns property is a
DataColumnCollection, so it has to know to which Table itself is attached
to. Then maybe DataColumnCollection would notify Table, which notifies
DataColumn.
I'll take a better look at the methods.

Thanks.
 
I was looking for a public method to do that. But now I know there's an
internal accessibility modifier, which solves the problem.

Thanks!
 
Back
Top