How do I populate a ComboBox at install time in WiX?

后端 未结 2 1453
野性不改
野性不改 2021-01-03 01:01

Edit: I\'ve updated the code below so that it now works, thanks to Rob\'s answer.

I\'ve found a couple of pages that show how to do this (http://www

2条回答
  •  独厮守ぢ
    2021-01-03 01:50

    This one is pretty old, however I had similar issue and would like to share what I've found, maybe this saves someone's time.

    to Make sure ComboBox table is created use EnsureTable, ensure CA doesn't overwrite defined value:

    
    
    
    
    
      
        
      
    
    
    
      
        
      
    
    
     
     
        
          
        
      
    

    I have a JavaScript function for filling ListItems: (yes, I know some of you don't like JS for custom actions, but it still is convenient enough)

    // Add ListItem to ComboBox or ListView at install time
    function AddListItemToMSI(Property, Order, Value, Text, Table) {
      try {
        var controlView = Session.Database.OpenView("SELECT * FROM " + Table);
        controlView.Execute();
    
        var record = Session.Installer.CreateRecord(4);
        record.StringData(1) = Property;
        record.IntegerData(2) = Order;
        record.StringData(3) = Value;
        record.StringData(4) = Text;
    
        controlView.Modify(7, record);
        controlView.Close();
      }
      catch (err) {
        ShowMessage('Couldn\'t add ListItem entry, error occured: ' + err.message, msiMessageTypeInfo);
      }
    
      return 1;
    }
    

    I call it from my other function (it is called as custom action) like this:

    var ComboBoxProperty = 'RS_INSTANCES';
    var InstanceFullName;
    for (i = 0; i < Names.length; i++) {
        InstanceFullName = GetInstanceName(Names[i]); //this function looks up full name in the registry
        AddListItemToMSI(ComboBoxProperty, i, InstanceFullName, '', 'ComboBox');
        if (i == 0) {
          Session.Property(ComboBoxProperty) = InstanceFullName;
        }
    }
    

    NOTE: I removed non-relevant pieces of code from last function to make it readable. P.S. always (I mean ALWAYS) use null, zero length and error checking, try/catch and ensure logging with something like this:

    function ShowMessage(text, options) {
        if (options == null) {
            var options = msiMessageTypeUser;
        }
        var oRecord = Session.Installer.CreateRecord(1);
        oRecord.StringData(1) = text;
        var response = Session.Message(options, oRecord);
        oRecord.ClearData();
        oRecord = null;
        response = null;
    }
    

提交回复
热议问题