Add and remove items to ListBox
Posted 22 August 2001 - 11:19
I made a dialog box with ListBox, EditBox and two buttons "Add" and "Remove". When dialog apaers ListBox is empty.I want enter text to Edit click Add and insert item in List. But CustomAction that I call from Add button doesn't work:
hDatabase = MsiGetActiveDatabase(hMSI);
sQuery = "SELECT * FROM ListBox WHERE Property='MYLIST'";
MsiDatabaseOpenView(hDatabase, sQuery, hView);
hRec=MsiCreateRecord(4);
MsiRecordSetString(hRec, 1, "MYLIST");
MsiRecordSetInteger(hRec, 2, 1);
MsiRecordSetString(hRec, 3, szValue);
MsiRecordSetString(hRec, 4, szValue);
MsiViewModify(hView, MSIMODIFY_INSERT_TEMPORARY, hRec);
MsiViewClose(hView);
But this code work fine if I call it before my dialog apears. Why. May be I need refresh ListBox?
Any Idea???
Posted 22 August 2001 - 13:02
If RESET does not work you need to make a near identical copy of your dialog. Your Add button will call the NewDialog event, after adding the new entry. to display the alternate dialog. This will result iin the list box being re-initialised with the new data.
Posted 23 August 2001 - 09:34
1).I 've tried add RESET event to Add Button. It's doesn't work. That interesting when I back to prev. dialog and step next to my dialog ListBox contains new item. ??????
2) In your second variant I don't understand what should happend when user click on Add button in identical copy of dialog.
May be I need use MSIMODIFY_REFRESH or MSIMODIFY_UPDATE in MsiViewModify when I insert Items.
Posted 23 August 2001 - 10:03
The listbox table is being updated. The problem is that the listbox dialog is filled on dialog creation. Unfortuanelty there is no way to refresh the contents of the listbox object other than displaying a new dialog,
Unfortunately you can not NewDialog the same dialog because Msi knows it already has the dialog loaded so you need to make a dialog that looks the same to your users but is different to msi.
You create
MyDialog and MyDialogAlt
On your add button for MyDialog you have two events
DoAction AddToList 1
NewDialog MyDialogAlt
On your add button for MyDialogAlt you have two events
DoAction AddToList 1
NewDialog MyDialog
In this way msi needs to build a new dialog and create a new list box with the latest data.