Securing Windows Forms DataGrid Columns
At times you may want to secure a particular column in a Windows Forms DataGrid so users have read-only access or no access to it at run time based on application security settings. We have created the mmDataGridTextBoxColumn control for this purpose.
By default, when you add a column to a Windows Forms DataGrid, Visual Studio adds an instance of the DataGridTextBoxColumn to the grid. If you have a DataGrid column that you want to secure, you need to replace it with mmDataGridTextBoxColumn as follows:
- Right-click the Windows Form that contains the DataGrid to view the form's source code.
- Change the data grid column's base class from:
System.Windows.Forms.DataGridTextBoxColumn
To:
OakLeaf.MM.Main.Windows.Forms.mmDataGridTextBoxColumn
You have to do this in two places--once where the column variable is declared, and again where the column is instantiated. For example:
Change:
private System.Windows.Forms.DataGridTextBoxColumn OrderID;
To:
private OakLeaf.MM.Main.Windows.Forms.mmDataGridTextBoxColumn OrderID;
And change:
this.OrderID = new System.Windows.Forms.DataGridTextBoxColumn();
To:
this.OrderID = new OakLeaf.MM.Main.Windows.Forms.mmDataGridTextBoxColumn();
- In the form's constructor after the call to InitializeComponent, set the column's ControlID property to a unique value. For example:
this.OrderID.ControlID = new System.Guid("8d86ae30-cfe1-4f46-945e-fc067c5a7892");
At run time when in Security Setup mode, just click on the secure column's header and the User Security Setup dialog appears allowing you to specify user/role access to the DataGrid column.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 05/19/08
Comment or report problem with topic
