c#excel Interop.XlDVType.xlValidateList自动完成IncellDropDown

我可以使用下面的代码在单元格中获取下拉列表

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. 

有谁知道如何配合事件,并具有自动完成function就像一个普通的Windows窗体combobox?

在这里,我试图解决这个问题。 这个对我有用。

 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); 

在这里,它将起作用,当你将细胞从头到尾连续填充而不留下任何细胞。 如果你将填充中间的单元格。 不起作用。