Hi,
I needed to make a TextBox on a DataGrid ReadOnly based on the condition of
another cell on its row.
I achieved this using a Custom Data Column Class "DacDGTextColLotNo" but I
can't get the TextBox to display its value when you leave the TextBox.
I figure that I need to use the SetColumnValueAtRow Method but I am
struggling to understand how.
I would appreciate any guidance.
My Create Grid Style Code on the Form:
........
CreateGridStyle = New DataGridTableStyle
........
........
If PurchStyle <> 1 Then
'Set Lot Nos Column
Dim DGTxtBoxLotNo AS New DacDGTextColLotNo
With DGTxtBoxLotNo
.MappingName = "LotNo"
.HeaderText = "Lot"
.Width = 50
.Alignment = HorizontalAlignment.Left
.NullText = ""
.Format = ""
.ReadOnly = True
End With
CreateGridStyle.GridColumnStyles.Add(DGTxtBoxLotNo )
..........
My Custom Column Style Class Code:
Public Class DataGridTextBoxColumn
Inherits DataGridTextBoxColumn
Public Sub New()
MyBase.New()
Me.MappingName = MappingName
Me.Format = Format
Me.Alignment = Alignment
Me.Width = Width
Me.ReadOnly = ReadOnly
Me.Headertext = Headertext
Me.NullText = NullText
End Sub
Protected Overrides Function GetColumnValueAtRow _
(ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer) As Object
Dim drv As DataRowView = CType([source].Current, DataRowView)
Try
Me.ReadOnly = Cint(drv("LotFlg")) <> 2
Catch
Me.ReadOnly = True
End try
End Function
End Class
Thanks
Doug