Smrf.NodeXL.ExcelTemplate.WorksheetContextMenuManager.AddSetColorContextMenuItem C# (CSharp) Méthode

AddSetColorContextMenuItem() protected méthode

protected AddSetColorContextMenuItem ( Microsoft oTable, Microsoft oClickedRange ) : void
oTable Microsoft
oClickedRange Microsoft
Résultat void
    AddSetColorContextMenuItem
    (
        Microsoft.Office.Tools.Excel.ListObject oTable,
        Microsoft.Office.Interop.Excel.Range oClickedRange,
        params String [] asColorColumnNames
    )
    {
        Debug.Assert(oTable != null);
        Debug.Assert(oClickedRange != null);
        Debug.Assert(asColorColumnNames != null);
        AssertValid();

        // If the selected cells aren't in a single column, a color can't be
        // set.

        Int32 iClickedColumnOneBased = oClickedRange.Areas[1].Column;

        foreach (Microsoft.Office.Interop.Excel.Range oClickedArea in
            oClickedRange.Areas)
        {
            if (oClickedArea.Columns.Count != 1 ||
                oClickedArea.Column != iClickedColumnOneBased)
            {
                return;
            }
        }

        // Check whether the selected cells are all in one of the specified
        // color columns.

        Microsoft.Office.Interop.Excel.ListColumn oColorColumn;

        foreach (String sColorColumnName in asColorColumnNames)
        {
            if (
                ExcelTableUtil.TryGetTableColumn(oTable.InnerObject,
                    sColorColumnName, out oColorColumn)
                &&
                oColorColumn.Range.Column == iClickedColumnOneBased
                )
            {
                CommandBar oTableContextCommandBar =
                    ExcelTableUtil.GetTableContextCommandBar(
                        m_oWorkbook.Application);

                CommandBarButton oSetColorButton =
                    (CommandBarButton)oTableContextCommandBar.Controls.Add(
                        MsoControlType.msoControlButton, 1, Missing.Value, 1,
                        true);

                oSetColorButton.Caption = ColorMenuItemCaption;
                oSetColorButton.Style = MsoButtonStyle.msoButtonCaption;

                oSetColorButton.Click += new
                    _CommandBarButtonEvents_ClickEventHandler(
                        this.oSetColorButton_Click);

                return;
            }
        }
    }