none
Collapse all Groups programatically RRS feed

  • Question

  • Hi

    I have created a list view to show appointments by category.  The code below works OK but the result is appointment grouped by category with all groups expanded.  I need to collapse all groups before the user sees it.  Is there a method or property for this that I have failed to find?  Failing that can it be done with Sendkeys?  Here is my current code.

    Dim exp As Outlook.Explorer = OutlookApp.ActiveExplorer
            Dim currentViews As Outlook.Views
            Dim categoryTableView As Outlook.View
            Dim categoryTable As Outlook.TableView
            Dim strViewName As String = "CategoryListView"
    
            Try
                'Get the current View collection
                currentViews = exp.CurrentFolder.Views
    
                'Does it contain CategoryListView?
                If currentViews(strViewName) Is Nothing Then
    
                    'Create a CategoryListView
                    currentViews.Add(strViewName, Outlook.OlViewType.olTableView, Outlook.OlViewSaveOption.olViewSaveOptionThisFolderOnlyMe)
                    categoryTableView = currentViews(strViewName)
    
                    'Get a reference to the newly added table view and adjust its properties
                    categoryTable = categoryTableView
                    categoryTable.AutoPreview = Outlook.OlAutoPreview.olAutoPreviewNone
                    categoryTable.AllowInCellEditing = False
                    categoryTable.SortFields.RemoveAll()
                    categoryTable.SortFields.Add("Categories")
                    categoryTable.ShowItemsInGroups = True
                    categoryTable.AutomaticGrouping = True
                    categoryTable.ViewFields.Remove("Recurrence")
                Else
                    categoryTableView = currentViews(strViewName)
                End If
                categoryTableView.Apply()
            Catch ex As Exception
                oAddin.ErrorMessage(ex, "", "")
            Finally
                If Not currentViews Is Nothing Then Marshal.ReleaseComObject(currentViews)
                If Not exp Is Nothing Then Marshal.ReleaseComObject(exp)
                If Not categoryTableView Is Nothing Then Marshal.ReleaseComObject(categoryTableView)
                If Not categoryTable Is Nothing Then Marshal.ReleaseComObject(categoryTable)
            End Try

     

    Mike VE

    Wednesday, October 31, 2012 9:37 AM

Answers

  • I am not aware of a way to do that programmatically.

    I can only think of simulating the Ctrl + (Num-) keystroke (the message list must have focus for this to work).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, October 31, 2012 9:08 PM
  • For the record I do not need to set the focus in code.  Below are the relevant lines of my code.

    'Apply the Category List view currentFolder.Views(strViewName).Apply()

    'Collapse all SendKeys.Send("^{SUBTRACT}")


    That seems to do the trick.


    Mike VE

    Saturday, November 3, 2012 4:20 PM

All replies

  • I am not aware of a way to do that programmatically.

    I can only think of simulating the Ctrl + (Num-) keystroke (the message list must have focus for this to work).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, October 31, 2012 9:08 PM
  • Thanks for that.  Is there a way to programatically give the message list focus? 

    Mike VE

    Thursday, November 1, 2012 10:16 AM
  • For the record I do not need to set the focus in code.  Below are the relevant lines of my code.

    'Apply the Category List view currentFolder.Views(strViewName).Apply()

    'Collapse all SendKeys.Send("^{SUBTRACT}")


    That seems to do the trick.


    Mike VE

    Saturday, November 3, 2012 4:20 PM
  • Hi Mike,

    I'm glade to hear that you have found work round, thanks for share it here, it's really helpful for other community members who have similar question.

    @Dmitry,

    Thanks for your great work too.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 5, 2012 7:28 AM
    Moderator