Hi,
I have resolved this problem.
For anyone interested, I believe that the problem was occuring because my
Class DataGridTextBoxColumn function "GetColumnValueAtRow" was over-riding
the Base method and the Row/Column value was not being writen back to the
Grid
The following code works:
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 s as Object = MyBase.GetColumnValueAtRow([source], rowNum)
Dim drv As DataRowView = CType([source].Current, DataRowView)
Dim fReadOnly As Boolean
Try
fReadOnly = drv("LotFlg").ToString <> "2"
Catch
fReadOnly = True
End try
Me.ReadOnly = fReadOnly
Return s
End Function
Doug
"Doug Bell" <dug@bigpond> wrote in message
news:ea*************@TK2MSFTNGP14.phx.gbl...
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