Category Archives: .NET Production Progs

Disabling the Cell in Datagrid

Though I’ve already created a program for this in the QCS of Purchasing, I opt to review the code which I’ve written before…In the Production progs, a feature was request by my colleague and I’ve program this

Public Class DatagridCellxCellEnable
Inherits DataGridTextBoxColumn
Private _col As Integer
Public Sub New(ByVal column As Integer)
_col = column
End Sub
Public Delegate Sub EnableCellEventHandler(ByVal sender As Object, ByVal e As DataGridEnableEventArgs)
Public Event CheckCellEnabled As EnableCellEventHandler
Protected Overloads Overrides Sub Edit(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
Dim enabled As Boolean
enabled = True
Dim e As DataGridEnableEventArgs
e = New DataGridEnableEventArgs(rowNum, _col, enabled)
RaiseEvent CheckCellEnabled(Me, e)
If e.EnableValue Then
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)
End If
End Sub
End Class

In my code i’ve included this

Dim numCols As Integer = Me.dtProdVolume.Columns.Count
Do While (i < numCols) Dim aColumnTextColumn As DatagridCellxCellEnable aColumnTextColumn = New DatagridCellxCellEnable(i) aColumnTextColumn.MappingName = Me.dtProdVolume.Columns(i).ColumnName AddHandler aColumnTextColumn.CheckCellEnabled, _ New DatagridCellxCellEnable.EnableCellEventHandler(AddressOf SetEnableValues) tableStyle.GridColumnStyles.Add(aColumnTextColumn) i = i + 1 Loop

an example c# code for this is available here