wyrd
Senior Contributor
Sort of hard for me to explain since I'm new to these concepts, but I'll try.
DataTable uses a DataView. However the DataTable only lets you get it's DefaultView (you cannot set it), and DataView lets you get or set the DataTable in which it belongs to.
I'm curious as to how the DataTable knows which DataView it belongs to. Is there an internal (for C#) reference for _dataView which DataView sets? Or is it handled differently?
ie;
I'm working on something similar. The ability to change dynamically how a class looks or is used based on a member class that it references. However I don't want the user to ruin the relationship by being able to set the Table's DefaultView to null or something else, which would leave the DataView.Table property pointing to a Table that doesn't use it. Or by setting the DataView.Table property to a Table, but not updating the Table.DefaultView, which would make the Table.DefaultView point to a DataView which it doesn't control.
What's the best way to handle this? How does the Table/DataView relationship work under the hood? The internal example I gave above still seems prone a little prone to error.
Thanks in advance.
DataTable uses a DataView. However the DataTable only lets you get it's DefaultView (you cannot set it), and DataView lets you get or set the DataTable in which it belongs to.
I'm curious as to how the DataTable knows which DataView it belongs to. Is there an internal (for C#) reference for _dataView which DataView sets? Or is it handled differently?
ie;
C#:
// In DataView class.
public DataTable
{
get {
return _table;
}
set {
// The old Table is no longer using this DataView.
_table.DataView = null;
_table = value;
_table.DataView = this;
// Note: DataView is an internal property.
}
}
// In DataTable class.
internal DataView
{
get {
return _dataView;
}
set {
_dataView = value;
}
}
public DefaultView
{
get {
return _dataView;
}
}
I'm working on something similar. The ability to change dynamically how a class looks or is used based on a member class that it references. However I don't want the user to ruin the relationship by being able to set the Table's DefaultView to null or something else, which would leave the DataView.Table property pointing to a Table that doesn't use it. Or by setting the DataView.Table property to a Table, but not updating the Table.DefaultView, which would make the Table.DefaultView point to a DataView which it doesn't control.
What's the best way to handle this? How does the Table/DataView relationship work under the hood? The internal example I gave above still seems prone a little prone to error.
Thanks in advance.
Last edited: