This is a migrated thread and some comments may be shown as answers.
Node validating event missing
13 Answers 93 Views
This is a migrated thread and some comments may be shown as answers.
Andrew Shyliuk
Top achievements
Rank 1
Andrew Shyliuk asked on 14 Dec 2010, 06:07 PM
Hello all,

I have RadTreeView control with some information on my form. User can change nodes text manually. After user changed node text I need validate it. If validation failed I have cancel this changes. How can I do it?
Events like NodeValidate are missing. Could you suggest how to solve this problem?

Best regards,
Andrew Shyliuk

13 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 14 Dec 2010, 09:53 PM
Hi Andrew,

You need to use the ValueValidating event. This is an extract from the docs
The Editing Lifecycle
A node enters edit mode
A node that is being displayed by the RadTreeView control is selected and the user presses the F2 key to bring the node into edit mode.
The RadTreeView control calls the BeginEdit() method and a new editor instance is initialized. It is available publicly through the ActiveEditor property in RadTreeView and is associated with the node that is about to be edited.
The editor fires its Editing event, which in turn triggers the firing of the RadTreeView Editing event. If either event is canceled, no further action takes place.
A text box based editor appears for input.
A node is brought out of edit mode
The editor determines if it wants to handle the keystroke.
The editor instance performs the action it has defined for the Enter key. Typically this indicates that edit mode should be exited and any changes made during the edit session should be applied to the node Text property.
In response to the action described in the previous step the EndEdit() method is called and the ValueChanged event is fired.
The RadTreeView fires the ValueValidating event which allows the user to hook up custom logic for verification. If the ValueValidating event does not succeed (e.Cancel is true), ValidationError event is fired to notify all listeners that the validation has failed.
The RadTreeView control sets the node Text property to the string representation of the editor Value property.

The full documentatation on editing nodes can be found here

hope that helps
Richard

0
Andrew Shyliuk
Top achievements
Rank 1
answered on 15 Dec 2010, 11:28 AM
Hello, Richard

Thanks for your explanation but I have two more questions:

1) When I set e.Cancel = true in ValueValidating event this event fires again with the same parameters and ActiveEditor.Value is the same too.
This is not good for me because before cancel Validating I show error message to user and this situation user see two error messages. How can I avoid the second fire of ValueValidating event?

2) About "and the user presses the F2 key to bring the node into edit mode". This is unusual way for editing in our customers view. The most usual way for editing - select node and click on it again (how to rename files and folders in Windows). Is it possible in Telerik RadTreeView?

Best regards,
Andrew Shyliuk
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 02:37 PM
Hi Andrew,

I think this should help. I've shown a simple exmaple of validating a node that ensures the word 'Node' is in the Node text when editing it.
for your second question, the simplest way to do this is shown in the example, but it does mean you can double click anywhere on the RadTreeView to put the current node into Edit mode.

Imports System.ComponentModel
Imports Telerik.WinControls.UI
  
Public Class Form1
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
    End Sub
  
    ''' <summary>
    ''' Ensure the edit text of teh current node contains the word 'Node'
    ''' </summary>
    Private Sub RadTreeView1_ValueValidating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RadTreeView1.ValueValidating
        If Not Me.RadTreeView1.ActiveEditor.Value.ToString.Contains("Node") Then
            e.Cancel = True
        End If
    End Sub
  
    ''' <summary>
    ''' Show an error box on error
    ''' </summary>
    Private Sub RadTreeView1_ValidationError(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTreeView1.ValidationError
        MessageBox.Show("Error")
    End Sub
  
    ''' <summary>
    ''' Simplest way to enable double click to edit
    ''' but will edit the current node event when double clicking away from the node
    ''' </summary>
    Private Sub RadTreeView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTreeView1.DoubleClick
        If Me.RadTreeView1.SelectedNode IsNot Nothing Then
            Me.RadTreeView1.SelectedNode.BeginEdit()
        End If
    End Sub
  
  
End Class

Hope that helps
Richard
0
Andrew Shyliuk
Top achievements
Rank 1
answered on 15 Dec 2010, 04:27 PM
Hello, Richard

1) In you sample Message box with text "Error" shows twice. But I don't need two message boxes, I need only one message box if user inputed incorrect text. Is it possible?

2) Renaming of files and folders in the windows and renaming of nodes in all TreeViews that I have seen is not on double click.
To rename folder in Windows you have click on it once wait a few seconds and click the folder again. A box should appear surrounding the folder name and you should be able to rename the folder.
Can I rename RadTreeView node in this way? As a rule it is a standard functionality...

Best regards,
Andrew Shyliuk
0
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 04:31 PM
Hi Andrew,

Curiously, if you press Enter after altering the text, you only get the messagebox once, though if you highlight another node, you get it twice. I suspect this is because of the call chain as detailed in my first post. I will look into this for you.

On your second question, it will probably involve a spearate thread and a timer. I'll see if I can work something out
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 04:54 PM
Hi Andrew,

This part shoud help you with the error box showing twice.. Can you give it a try and let me know
Imports System.ComponentModel
Imports Telerik.WinControls.UI
  
Public Class Form1
  
    Private m_OnError As Boolean
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
    End Sub
  
  
    ''' <summary>
    ''' Ensure the edit text of the current node contains the word 'Node'
    ''' </summary>
    Private Sub RadTreeView1_ValueValidating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RadTreeView1.ValueValidating
        If Not Me.RadTreeView1.ActiveEditor.Value.ToString.Contains("Node") Then
            e.Cancel = True
        End If
    End Sub
  
    ''' <summary>
    ''' Show an error box on error
    ''' </summary>
    Private Sub RadTreeView1_ValidationError(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTreeView1.ValidationError
        If Not m_OnError Then
            MessageBox.Show("Error")
            m_OnError = True
        End If
    End Sub
  
    Private Sub RadTreeView1_SelectedNodeChanging(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.RadTreeViewCancelEventArgs) Handles RadTreeView1.SelectedNodeChanging
        e.Cancel = m_OnError
    End Sub
End Class

Hope that helps
Richard
0
Andrew Shyliuk
Top achievements
Rank 1
answered on 15 Dec 2010, 05:01 PM
Hello, Richard

About first question. I am waiting for more universal solution that will work if I press Enter, highlight another node or another control.

About second question. I'll implement timer myself if there are no other way of resolving this problem.

Best regards,
Andrew Shyliuk
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 05:03 PM
Hi Andrew,

Already tried the second one. Have a look at this and see if it works for you
Imports System.ComponentModel
Imports Telerik.WinControls.UI
  
Public Class Form1
  
    Private m_OnError As Boolean
    Private WithEvents m_BackgroundWorker As New BackgroundWorker()
    Private m_Clicks As Integer
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
    End Sub
  
  
    ''' <summary>
    ''' Ensure the edit text of the current node contains the word 'Node'
    ''' </summary>
    Private Sub RadTreeView1_ValueValidating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RadTreeView1.ValueValidating
        If Not Me.RadTreeView1.ActiveEditor.Value.ToString.Contains("Node") Then
            e.Cancel = True
        End If
    End Sub
  
    ''' <summary>
    ''' Show an error box on error
    ''' </summary>
    Private Sub RadTreeView1_ValidationError(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTreeView1.ValidationError
        If Not m_OnError Then
            MessageBox.Show("Error")
            m_OnError = True
        End If
    End Sub
  
    Private Sub RadTreeView1_SelectedNodeChanging(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.RadTreeViewCancelEventArgs) Handles RadTreeView1.SelectedNodeChanging
        e.Cancel = m_OnError
    End Sub
  
    Private Sub RadTreeView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTreeView1.Click
        If Me.RadTreeView1.SelectedNode IsNot Nothing Then
            m_Clicks = m_Clicks + 1
            If m_Clicks = 2 Then
                Me.RadTreeView1.SelectedNode.BeginEdit()
            Else
                m_BackgroundWorker.RunWorkerAsync()
            End If
        End If
    End Sub
  
    Private Sub BackgroundWorker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles m_BackgroundWorker.DoWork
        System.Threading.Thread.Sleep(1000)
    End Sub
  
    Private Sub BackgroundWorker_RunWorkCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles m_BackgroundWorker.RunWorkerCompleted
        m_Clicks = 0
    End Sub
  
End Class


Can you let me know more details about what you need for the first
Richard
0
Andrew Shyliuk
Top achievements
Rank 1
answered on 15 Dec 2010, 05:20 PM
Hello, Richard

About first. Yes Error message shows once. But it doesn't show if I input incorrect text again. And I cannot select other node after message box showed even I enter correct text.

About second. Click and click after a few seconds works only in the first time.

Test your solution before post, please.

Best regards,
Andrew Shyliuk
0
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 05:27 PM
Andrew,

On my PC, the double click works as expected. I can click-wait-click and the node moves into edit mode each time.
I will look into the first one for you again but these are suggestions that I am looking for your feedback from. They are not fully tested.
Richard
0
Andrew Shyliuk
Top achievements
Rank 1
answered on 15 Dec 2010, 06:11 PM
Richard,

I'm working with version Q3 2010. Do you test you code with this controls version.
What operating system on your computer?
Could you provide archive with your solution?

Best regards,
Andrew Shyliuk
0
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 06:16 PM
Hello Andrew,

I'm also using 2010 Q3. My OS is Windows 7 64 bit. As soon as I get the time, I will create a small Jing video for you to see, so you can let me know if there is something I'm missing when trying it out.
Regards,
Richard
0
Andrew Shyliuk
Top achievements
Rank 1
answered on 15 Dec 2010, 06:24 PM
Hello, Richard

Thanks but do not bother creating video I don't need it. Could you provide only solution with sample code? I have Windows 7 64 bit and I can test it.

Best regards,
Andrew Shyliuk
Asked by
Andrew Shyliuk
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Andrew Shyliuk
Top achievements
Rank 1
Share this question
or