本文介绍了时间:2019-01-16标签:c#excelinterop.xlDVType.xlValidateList自动完成IncellDropDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下代码在单元格中下拉菜单

I am able to get dropdown in a cell using the code below

               Interop.Range validationAddressRange = ws.Worksheet.get_Range(startAddress, endAddress);
                validationAddressRange.Select();
                validationAddressRange.Cells.Validation.Delete();
                validationAddressRange.Cells.Validation.Add(Type: Interop.XlDVType.xlValidateList,
                AlertStyle: Interop.XlDVAlertStyle.xlValidAlertStop, Formula1: formula);
                validationAddressRange.Cells.Validation.IgnoreBlank = true;
                validationAddressRange.Cells.Validation.InCellDropdown = true;
                validationAddressRange.Cells.Validation.ErrorMessage = "Invalid entry. Click 'Retry' to update the cell value, or 'Cancel' to undo the change made to the cell.";
                validationAddressRange.Cells.Validation.ErrorTitle = "Invalid Data Error";
                validationAddressRange.Cells.Validation.ShowError = true;
                ws.Worksheet.Cells[1,1].Select(); //selects the top-leftmost cell since excel doesn't furnish a de-select option.

有人像常规的Windows窗体组合框一样知道如何绑定事件并具有自动完成功能吗?

Does anyone know how to tie in events and have autocomplete feature just like a regular windows form combobox?

推荐答案

在这里,我尝试解决此问题.它对我有用.

Here, I tried to solve this. it works for me.

var list = new System.Collections.Generic.List<string>();
list.Add("RFP");
list.Add("2nd Review");
list.Add("RESHOOT");
var flatList = string.Join(", ", list.ToArray());

var cell = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells.get_Range("B1");;
cell.Validation.Delete();
cell.Validation.Add( XlDVType.xlValidateList,
    XlDVAlertStyle.xlValidAlertInformation,
    XlFormatConditionOperator.xlBetween,
    flatList,
    Type.Missing);

在这里,当您从头到尾连续填充单元格而不离开任何单元格时,它将起作用.如果您要填充中间的单元格.不起作用.

Here, It will work when you will fill the cells from first to last continuously without leaving any cell. if you will fill the cell in the middle. It will not work.

这篇关于时间:2019-01-16标签:c#excelinterop.xlDVType.xlValidateList自动完成IncellDropDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:40