c# - How to get the value of selected item in a xlDropDown which is added programmatically to a Excel sheet cell -
the next code shows way created drop downs programmatically. works fine. need value of specific dropdown of cell.
microsoft.office.interop.excel.dropdowns xldropdowns; microsoft.office.interop.excel.dropdown xldropdown; xldropdowns = ((microsoft.office.interop.excel.dropdowns)(sheet.dropdowns(type.missing))); xldropdown = xldropdowns.add((double)rag.left, (double)rag.top, (double)rag.width, double)rag.height, true); var dropdownlist = {"aaaa","bbbb","cccc","dddd"}; int x = 0; foreach (var item in dropdownlist) { x++; xldropdown.additem(item); }
this how tried xldropdown value. currentcell cell have drop down
columnval = currentcell.text; // didnt give output
or
var dd = (microsoft.office.interop.excel.dropdown)currentcell.dropdowns(type.missing);
i know 2nd 1 wrong, because cell range , drop downwards 2 different things. tried options, still couldnt find solution. please help me
more clearly, want access specific cell(currentcell), , xldropdown contains , value it
first need reference drop downwards you've added:
*assuming there's 1 drop down, below do
xldropdown = ((excel.dropdown)(xldropdowns.item(1)));
then need access .get_list()
property of excel.dropdown
while making sure has been selected.
example:
if (xldropdown.value > 0) { sht.get_range("a1").value = xldropdown.get_list(xldropdown.value); } else { throw new exception("nothing selected yet"); }
identifying dropdowns:
you each loop on xldropdowns
collection , grab .name
, .listindex
of each xldropdown
?
foreach (excel.dropdown xldd in xldropdowns) { messagebox.show(xldd.name + ", " + xldd.listindex); }
c# asp.net excel office-interop
No comments:
Post a Comment