Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

VS 2015 Extensibility Combo Update when dynamically removing items from list

$
0
0

I have a VS 2015 Extensibility project in which I have a combo list of items and a button. The button, opens a WPF tool window that allows the user to alter/add a new item to the combo list, or can remove the list.

If I add an item to the list on my tool window, it successfully adds the item, also it can successfully remove the item. The problem is if I remove the currently selected item in the combo list does not refresh until the user clicks on it. This could cause other problems for the user because the entry selected is no longer in the list. How can I get the combo list to reflect the update. Below shows the package code that initializes the objects and where I am trying to refresh the combo.

public MyPackageCommand( Package package, IMyService myService )
{
    if( package == null )
    {
        throw new ArgumentNullException( "package" );
    }

    _package = package;
    _myService  = myService ;

    if( CommandService != null )
    {
        var dropDownCombo = new CommandID(
            PackageGuids.guidMyServicePackageCmdSet,
            (int)PackageIds.cmdIdCombo );
            var dropDownComboCommand = new OleMenuCommand( OnDropDownCombo, dropDownCombo );
            dropDownComboCommand.ParametersDescription = "$";
            CommandService.AddCommand( dropDownComboCommand );


        var dropDownComboList = new CommandID(
            PackageGuids.guidMyServicePackageCmdSet,
            (int)PackageIds.cmdIdComboGetList );
        var dropDownComboListCommand = new OleMenuCommand( OnDropDownComboList, dropDownComboList );
        CommandService.AddCommand( dropDownComboListCommand );

        var cmdEdit = new CommandID(
            PackageGuids.guidMyServicePackageCmdSet,
            (int)PackageIds.cmdIdEditor);
        var buttonCommand = new OleMenuCommand( ShowEditorWindow , cmdEdit );
        CommandService.AddCommand( buttonCommand );
    }

    _currentComboSelection = _myService.FindValueKey();
 }
 private void ShowEditorWindow( object sender, EventArgs e )
 {
    ToolWindowPane window = _package.FindToolWindow( typeof(ToolWindowEditor), 0, true );
    if( (window == null) || (window.Frame == null) )
    {
        using (ResXResourceSet resource = new ResXResourceSet( @".\VSPackage.resx" ))
        {
            throw new NotSupportedException( resource.GetString( "CanNotCreateWindow" ) );
        }
    }
    var control = window.Content as Editor;

    if( control != null )
    {
        var context = control.DataContext as EditorViewModel;
        if( context != null )
            context.MyEvent += OnMyEventHandler;
    }

    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
    ErrorHandler.ThrowOnFailure( windowFrame.Show() );


}

private void OnMyEventHandler( object sender, EventArgs eventArgs )
{
    // how do i get at the combo control here?
}

The drop down combo event re-populates the list correctly but only when you click on it, but I need to do this before they click the drop down and I don't see how to get at the combo for my event handler. The code below is what works for the combo and explains better why I am unsure of updating the extensible combo box.

    private void OnDropDownComboList( object sender, EventArgs e )
    {
        var eventArgs = e as OleMenuCmdEventArgs;

        if( eventArgs == null )
            throw new ArgumentException( "Event arguments are required." );

        IntPtr outPtr = eventArgs.OutValue;

        if( outPtr != IntPtr.Zero )
        {
            _comboSelections = GetComboSelections();
            Marshal.GetNativeVariantForObject( _comboSelections, outPtr );
        }
        else
        {
            throw (new ArgumentException( "The output argument is required." ));
        }

    }
Thanks in advance, Kent




Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>