How do you call a method inside that same method??? RRS feed

  • Question

  • This is my code:

    Private Sub ExpandAllTreeViewItems(currentTreeViewItem As TreeViewItem)
    If Not currentTreeViewItem.IsExpanded Then
    currentTreeViewItem.IsExpanded = True
    currentTreeViewItem.Dispatcher.BeginInvoke(Function() ExpandAllTreeViewItems(currentTreeViewItem))
    For i As Integer = 0 To currentTreeViewItem.Items.Count - 1
    Dim child As TreeViewItem = DirectCast(currentTreeViewItem.ItemContainerGenerator.ContainerFromIndex(i), TreeViewItem)
    End If
    End Sub

    This is the troubled line:

    currentTreeViewItem.Dispatcher.BeginInvoke(Function() ExpandAllTreeViewItems(currentTreeViewItem))

    when I try to use this it throws an error saying that "Expression does not produce a value"

    can someone please tell me what I am doing wrong.

    Thank you

    Wednesday, October 29, 2014 9:34 PM


  • Hi,

    You could try to use recursion.
    Recursion occurs when a method calls itself. Recursive functions need special stop conditions. Otherwise they will infinitely continue calling themselves. With the ByRef keyword, we provide a way to stop a recursive function.

    For more information about recursion,please see links below:



    Best Regards,

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Jonny_D Friday, November 7, 2014 5:19 AM
    Friday, October 31, 2014 3:34 AM