M
Matt
Hi,
I've been thinking about how to do this, but can't think of a solution.
I have a class that is derived from System.Web.UI.WebControls.DataGrid which
works a treat, but I'd like to extend the DataGridColumnCollection class
(property of DataGrid) just a fraction by allowing a string indexer. i.e.
rather than using
myDataGrid.Columns[7].Visible = false;
I'd like to be able to do this:
myDataGrid.Columns["Balance"].Visible = false;
Background: We have a design where only certain columns are shown depending
on the currently logged in user's roles. Management tend to keep changing
the layout by moving columns around, creating havoc in the code behind as
hiding/showing columns is currently done by using the indexer as shown
above. Moving column 7 to column 9 causes problems if you forget to change
the role checks for columns above 8 etc. I've introduced int constants now
for column names to help a bit, but still can create problems if not done
correctly. It would be nicer to use "Key" names. All columns of myDataGrid
derive from their parent (eg myNamespace.BoundColumn :
System.Web.UI.WebForms.BoundColumn) which also contain a property "Key" of
type string (from an interface).
DataGridColumnCollection cannot be inherited.
Anyone have an idea on how to do this without creating a new property (e.g.
myColumns of type myDataGridColumnCollection).
TIA.
Matt.
I've been thinking about how to do this, but can't think of a solution.
I have a class that is derived from System.Web.UI.WebControls.DataGrid which
works a treat, but I'd like to extend the DataGridColumnCollection class
(property of DataGrid) just a fraction by allowing a string indexer. i.e.
rather than using
myDataGrid.Columns[7].Visible = false;
I'd like to be able to do this:
myDataGrid.Columns["Balance"].Visible = false;
Background: We have a design where only certain columns are shown depending
on the currently logged in user's roles. Management tend to keep changing
the layout by moving columns around, creating havoc in the code behind as
hiding/showing columns is currently done by using the indexer as shown
above. Moving column 7 to column 9 causes problems if you forget to change
the role checks for columns above 8 etc. I've introduced int constants now
for column names to help a bit, but still can create problems if not done
correctly. It would be nicer to use "Key" names. All columns of myDataGrid
derive from their parent (eg myNamespace.BoundColumn :
System.Web.UI.WebForms.BoundColumn) which also contain a property "Key" of
type string (from an interface).
DataGridColumnCollection cannot be inherited.
Anyone have an idea on how to do this without creating a new property (e.g.
myColumns of type myDataGridColumnCollection).
TIA.
Matt.