Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Ribbon1.cs using Ribbon Designer (ie, no XML)

I am trying to clear the contents of a Drop Down list before repopulating the list with new data.

I have tried using Invalidate() in several places but I can't get it to work.

The flow of the Addin is as followed:

Copy text to clipboard -> works

Click Search -> works

Get new Data from Database using text from Clipboard -> works

Clear Dropdown -> doesn't work

Populate Drop Down with data. -> Does work but add items to drop down instead of clearing it first

Thanks in advance


using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
using System.Data.Odbc;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Tools.Ribbon;

namespace MSTEST
{
    public partial class Ribbon1 : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;
        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {
            this.ribbon = RibbonUI;
        }

        private void eventDB(object sender, RibbonControlEventArgs e)
        {
            RibbonUI.Invalidate();
            //this.ribbon.InvalidateControl("resultsDB");
            string getTextFromClipboard = Clipboard.GetText();
            string queryString = "select distinct file_path as FP, case_id as CS, date_added from documents CONTAINS(documents.file_path, '" + getTextFromClipboard + "') group by case_id,file_path, datE_added order by Date_Added DESC";
            using (OdbcConnection odbcConnection = new OdbcConnection("dsn=Needles;UID=dba;PWD=sql;"))
            {
                OdbcCommand command = new OdbcCommand(queryString, odbcConnection);
                try
                {
                    odbcConnection.Open();
                    OdbcDataReader reader = command.ExecuteReader();
              //      ribbon.InvalidateControl("resultsDB");
                    int i = 0;
                    while (reader.Read())
                    {
                        // Being DropDown Populate
                        RibbonDropDownItem item = this.Factory.CreateRibbonDropDownItem();
                        item.Label = reader["FP"].ToString();
                        resultsDB.Items.Add(item);
                        //MessageBox.Show(reader["CS"].ToString());
                        // End DropDown Populate
                        i = i + 1;
                    }

                    reader.Close();
                    odbcConnection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        public string GetCustomUI(string RibbonID)
        {
            throw new NotImplementedException();
        }
    }
}


What I have tried:

I have tried all sorts of variations of ribbon.Invalidate. I think it may have to do with how outlook loses focus on the ribbon once the 'search' button is clicked.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900