Question about ValidatedDataGridTextColumn

Question about ValidatedDataGridTextColumn

Old forum URL: forums.lhotka.net/forums/t/7609.aspx


Fel posted on Friday, September 11, 2009

Is it possible to set ValidatedDataGridTextColumn to edit mode that a user don't need to click two times to be able change value in it?
If yes, what I need to do?

Thanks

RockfordLhotka replied on Friday, September 11, 2009

I don't know. I think it changes modes when it is clicked the first time, maybe you can have it set focus automatically after that mode change?

pondosinat replied on Friday, September 11, 2009

Yes. We're doing this now by subclassing DataGrid and handling the PreparingCellForEdit event. Here is the code.

Imports Csla.Silverlight

Public Class EditableGridBase

Inherits DataGrid

Public Sub New()

AddHandler CurrentCellChanged, AddressOf dg_CurrentCellChanged

AddHandler PreparingCellForEdit, AddressOf dg_PreparingCellForEdit

End Sub

Private Sub dg_CurrentCellChanged(ByVal sender As Object, ByVal e As EventArgs)

EnterEditMode()

End Sub

Sub EnterEditMode()

Try

BeginEdit()

Catch ex As Exception

End Try

End Sub

Private Sub dg_PreparingCellForEdit(ByVal sender As Object, ByVal e As DataGridPreparingCellForEditEventArgs)

Dim txt As TextBox = Nothing

If TypeOf e.Column Is ValidatedDataGridTextColumn Then

Dim sp = TryCast(e.EditingElement, StackPanel)

txt = TryCast(sp.Children(0), TextBox)

Dim p = TryCast(sp.Children(1), PropertyStatus)

txt.Width = e.Column.ActualWidth - 2

p.Visibility = Windows.Visibility.Collapsed

ElseIf TypeOf e.Column Is DataGridCheckBoxColumn Then

Dim ch = TryCast(e.EditingElement, CheckBox)

If ch IsNot Nothing Then

ch.Focus()

ch.IsChecked = Not ch.IsChecked.Value

Return

End If

Else

txt = TryCast(e.EditingElement, TextBox)

End If

If txt IsNot Nothing Then

txt.SelectionLength = txt.Text.Length

txt.Focus()

End If

End Sub

End Class

Copyright (c) Marimer LLC