ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add DropDown at Runtime Visual Studio Shared AddIn (https://www.excelbanter.com/excel-programming/380697-add-dropdown-runtime-visual-studio-shared-addin.html)

aferriere

Add DropDown at Runtime Visual Studio Shared AddIn
 
Hi

I have created a shared add in for Excel using Visual Studio.NET 1.1.
Please note I am NOT using Visual Studio Tools for Office. I am trying
to add a combo box to the active worksheet at runtime.
I am not able to figure out what code to do so. The following
approaches DONT work

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Combo Box.1", Link:=False,
_
DisplayAsIcon:=False, Left:=65.25, Top:=40.5, Width:=72,
Height:=18)

ActiveSheet.DropDowns.Add()

From within the code the OLEObjects and DropDowns class dont have the

Add method. I can use the Add method from VBA but not from VS.NET. Is
it even possible to do this in VS.NET ?

Thanks


aferriere

Add DropDown at Runtime Visual Studio Shared AddIn
 

Replying to my own post here. But if any of you guys are trying to do
something similiar here is the working code

string []vaProducts={"Water", "Oil", "Chemicals", "Gas"};
Worksheet xlwsSheet;
xlwsSheet = (Worksheet)_excel.ActiveWorkbook.ActiveSheet;
Range Target;
Target = xlwsSheet.get_Range("A9","A9");
Excel.DropDowns xlDropDowns;
Excel.DropDown xlDropDown;
xlDropDowns = ((Excel.DropDowns)(xlwsSheet.DropDowns(Missing.Val ue)));
xlDropDown=xlDropDowns.Add((double)Target.Left,(do uble)Target.Top,(double)Target.Width,(double)Targe t.Height,true);
for (int i=0;i<vaProducts.Length; i++)
{
xlDropDown.AddItem(vaProducts[i],i);
}



All times are GMT +1. The time now is 05:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com