Fill Value List in .Net Custom Action From Code

Hello,

is there a way to e.g set the Items of a ComboBox from within the Custom Actions .Net Code? This way I can set the items of the combobox to the strings of an Enum without manually checking that they are in sync if it changes.

Hope they is a solution for this.

Hi,

You can use ‘InvokeAssemblyMethod’ method to call a managed method from the action’s script. The method must be public and take a single string parameter.

For example:

C#

public object[] GetEnumValues(string value) {
return Enum.GetNames(typeof(DayOfWeek));
}

VBScript

InvokeAssemblyMethod(“GetEnumValues”, “”)

Regards,
Paul.

thanks for the hint it works well, except for one thing:I can not access the members of the array.
Do I need to conver the array?

I have the following vbScipt code:

dim EValues
EValues = InvokeAssemblyMethod(“GetEnumValues”, “”)
for each i in EValues
MsgBox "Current i is " & i
next

It always returns a “type mismatch” error, but when debugging the script I can see that the EVAlues variable contains the correct values.
Best regards,
quirrel

Hi Quirrel,

Sorry, it look’s like VBScript can’t handle the array type that is being returned (works fine in Javascript). You can either switch to using Javascript, or return a string and split it in VBScript, i.e.

C#

[code]public string GetNames(string arg) { return string.Join(", ", Enum.GetNames(typeof(EnvironmentVariableTarget))); }[/code]

VBScript

[code]dim EValuesEValues = Split(InvokeAssemblyMethod(“GetNames”, “”), ", ")For Each x in EValues MsgBox xNext[/code]

Regards,
Paul.

thanks for pointingt this out, I really thought I missed something here.
That one now works just fine.
May be you can give a final hint on how to pass a stringparameter to the c# method?
Calling
EValueName=“EProductVersionState”
EValues = Split(InvokeAssemblyMethod(“GetEnumValues”, EValueName), “|”)
throws an exception…
Best regards,
quirrel

Hi Quirrel,

Just tested it here and passing arguments works fine, I can’t see anything wrong with the code you’ve posted. What is the error that you’re getting?

Regards,
Paul.

ok, the parameter “transmission” works well, it was a problem within the method that I called Do you have a hint on how to preselect the previously selected value?