Hi all,
After binding my listobject/excelsheet with database I put following code to add combobox into each cell of the column.
Excel.Worksheet mainSheet = (Excel.Worksheet)Globals.ThisWorkbook.Sheets[1];
Excel.Range oRange = mainSheet.get_Range("C10", missing);
oRange.Validation.Add(Excel.XlDVType.xlValidateList, Excel.XlDVAlertStyle.xlValidAlertStop, Excel.XlFormatConditionOperator.xlBetween, "=C11:C150", " ");
oRange.Validation.IgnoreBlank = false;
oRange.Validation.InCellDropDown = true;
And here getting error for last line i.e.
oRange.Validation.InCellDropDown = true;
Here I have following problems:
1. The data appears into each combobox is depending only on the data into this column i.e. each combobox has all/duplicates data of that column. But my requirement is: this combobox should have all data corresponding to that column in database either that data present in excelsheet or not.
Is it possible to add some method or formula that grab all data from the respecting column into "formula1" & "formula2" argument of above Add method
Thank you

Seroius error while having combobox into each column's cells
Susan_MSFT
Hi
More details of the Validation.Add function can be found in the MSDN documentation at http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.excel.validation.add(VS.80).aspx. However, I realised the interop documentation is not complete. If you look at the documentation provided with Excel installation itself for the Validation.Add function, you will find more details:
Adds data validation to the specified range.
expression.Add(Type, AlertStyle, Operator, Formula1, Formula2)
expression Required. An expression that returns a Validation object.
Type Required XlDVType. The validation type.
AlertStyle Optional Variant. The validation alert style. Can be one of the following XlDVAlertStyle constants: xlValidAlertInformation, xlValidAlertStop, or xlValidAlertWarning.
Operator Optional Variant. The data validation operator. Can be one of the following XlFormatConditionOperator constants: xlBetween, xlEqual, xlGreater, xlGreaterEqual, xlLess, xlLessEqual, xlNotBetween, or xlNotEqual.
Formula1 Optional Variant. The first part of the data validation equation.
Formula2 Optional Variant. The second part of the data validation when Operator is xlBetween or xlNotBetween (otherwise, this argument is ignored).
Remarks
The Add method requires different arguments, depending on the validation type, as shown in the following table.
As you will notice in Formula1 for xlValidateList you can specify a list of values separated with commas.
So you can have some other function which gets the data from the database and populate the Excel Formula1 as comma-delimited list.
oRange.Validation.Add(Excel.XlDVType.xlValidateList, Excel.XlDVAlertStyle.xlValidAlertStop, Excel.XlFormatConditionOperator.xlBetween, "Australia, Canada, USA", " ");
Hope that helps!
-Nikhil
Mark_E475
Hi Nikhil,
Yeah, I have already followed the above document. And also got the idea how to put comma -delimited list as in following:
oRange.Validation.Add(Excel.XlDVType.xlValidateList, Excel.XlDVAlertStyle.xlValidAlertStop, Excel.XlFormatConditionOperator.xlBetween, "Australia, Canada, USA", " ");
But the problem that I have:
I have more that 500 elements into database and putting 500 elements separated by comma is not the good idea. Thats why I asked for if there any other possible way.
Thank you
DLLnewbie
Hi All,
Still I didnt get any perfect solution here.
Please assist me.
Thank you
mma01
Hi Prashant. I am also having the same problem. I am having list of 120 + countries which is comma sepertaed. When I am trying to feed it to methode
oRng.Validation.Add(Excel.
XlDVType.xlValidateList, Missing.Value, Excel.XlFormatConditionOperator.xlBetween, strResults[1], Missing.Value);where strResults[1] is the coma spertaed list of values. The end result is I am only getting first 30 valuse listed in my drop down list.
Please help me out. If it is not possible in this way then suggest me some other way of dogin as you might have done.
Thanks in Advance.