Combo box programming with c#

%3CLINGO-SUB%20id%3D%22lingo-sub-1395806%22%20slang%3D%22en-US%22%3ECombo%20box%20programming%20with%20c%23%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1395806%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3ECan%20someone%3C%2FSPAN%3E%20%3CSPAN%3Ecan%3C%2FSPAN%3E%20%3CSPAN%3Eadvise%3C%2FSPAN%3E%20%3CSPAN%3Eme%3C%2FSPAN%3E%20%3CSPAN%3Ehow%3C%2FSPAN%3E%20%3CSPAN%3Eto%3C%2FSPAN%3E%20%3CSPAN%3Eprogrammatically%3C%2FSPAN%3E%20%3CSPAN%3Eset%3C%2FSPAN%3E%20up%20%3CSPAN%3Ea%3C%2FSPAN%3E%20%3CSPAN%3Eform%3C%2FSPAN%3E%20%3CSPAN%3Econtrol%3F%3C%2FSPAN%3E%20I'll%20explain%20the%20problem%20on%20the%20example.%20My%20program%20opens%20a%20table%20Template.xlsx%2C%20completes%20the%20list%20of%20contact%20points%2C%20and%20saves%20it%20as%20a%20Form.xlsx.%20The%20end%20user%20should%20add%20a%20name%20to%20the%20Form.xlsx%20and%20select%20one%20point%20of%20contact.%20He%20uses%20a%20combo%20box%20control.%20When%20selects%20a%20contact%20point%2C%20their%20index%20is%20saved%20in%20cell%20C4%2C%20and%20the%20relevant%20cells%20show%20the%20street%2C%20city%2C%20zip%20code.%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22List1.GIF%22%20style%3D%22width%3A%20346px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F192306iB9FE2B24F7314418%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22List1.GIF%22%20alt%3D%22List1.GIF%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EProgram%20written%20in%20C%23%2C%20populates%20the%20contact%20table%20with%20the%20current%20values%2C%20and%20insetrs%20the%20current%20formula%20values.%20I%20can't%20program%20the%20combo%20box%20control.%3C%2FP%3E%3CP%3EThe%20macro%20record%20for%20setting%20up%20the%20combo%20box%20is%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20ActiveSheet.Shapes.Range(Array(%22Drop%20Down%201%22)).Select%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20Application.CutCopyMode%20%3D%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20With%20Selection%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.ListFillRange%20%3D%20%22List!%24C%242%3A%24C%245%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.LinkedCell%20%3D%20%22C4%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.DropDownLines%20%3D%208%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Display3DShading%20%3D%20False%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20End%20With%3C%2FP%3E%3CP%3EI%20don't%20know%20how%20to%20write%20this%20sequence%20in%20C%23.%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20private%20void%20CreateForm()%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20string%20templatePath%20%3D%20%40%22c%3A%5CWork%5CTemplate.xlsx%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20string%20formPath%20%3D%20%40%22c%3A%5CWork%5CForm.xlsx%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(File.Exists(formPath))%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20File.Delete(formPath)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20exApl%20%3D%20new%20Microsoft.Office.Interop.Excel.Application%20%7B%20Visible%20%3D%20false%20%7D%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20wBook%20%3D%20exApl.Workbooks.Open(templatePath)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20wShtFrm%20%3D%20wBook.Worksheets%5B%22Form%22%5D%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20wShtLst%20%3D%20wBook.Worksheets%5B%22List%22%5D%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20int%20iLast%20%3D%205%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20for%20(int%20i%20%3D%202%3B%20i%20%26lt%3B%3D%20iLast%3B%20i%2B%2B)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtLst.Cells%5Bi%2C%201%5D%20%3D%20%22CP%22%20%2B%20i%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtLst.Cells%5Bi%2C%202%5D%20%3D%20%22Street%20%22%20%2B%20i%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BwShtLst.Cells%5Bi%2C%203%5D%20%3D%20%22City%20%22%20%2B%20i%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtLst.Cells%5Bi%2C%204%5D%20%3D%2012300%20%2B%20i%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtFrm.Range%5B%22B3%22%5D.FormulaR1C1Local%20%3D%20%24%22%3DINDEX(List!R2C1%3AR%7BiLast%7DC4%3BR4C3%3B1)%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtFrm.Range%5B%22B4%22%5D.FormulaR1C1Local%20%3D%20%24%22%3DINDEX(List!R2C1%3AR%7BiLast%7DC4%3BR4C3%3B2)%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtFrm.Range%5B%22B5%22%5D.FormulaR1C1Local%20%3D%20%24%22%3DINDEX(List!R2C1%3AR%7BiLast%7DC4%3BR4C3%3B3)%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtFrm.Range%5B%22B6%22%5D.FormulaR1C1Local%20%3D%20%24%22%3DINDEX(List!R2C1%3AR%7BiLast%7DC4%3BR4C3%3B4)%22%3B%3C%2FP%3E%3CP%3E%2F%2F%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20_contrl%20%3D%20wShtFrm.Shapes.Range%5B%22Drop%20Down%201%22%5D%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%3F%3F%3F%3F%3F%3F%3F%3F%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F_contrl.ListFillRange%20%3D%20%24%22List!%24C%242%3A%24C%24%7BiLast%20%7D%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F_contrl.LinkedCell%20%3D%20%22C4%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F_contrl.DropDownLines%20%3D%204%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F_contrl.Display3DShading%20%3D%20false%3B%3C%2FP%3E%3CP%3E%2F%2F%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtFrm.Protect(Contents%3A%20true)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtFrm.EnableSelection%20%3D%20XlEnableSelection.xlUnlockedCells%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtLst.Protect(Contents%3A%20true)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wShtLst.EnableSelection%20%3D%20XlEnableSelection.xlUnlockedCells%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20wBook.Close(true%2C%20formPath)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20exApl.Quit()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1395806%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ENeed%20Help%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1405385%22%20slang%3D%22en-US%22%3ERe%3A%20Combo%20box%20programming%20with%20c%23%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1405385%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F670070%22%20target%3D%22_blank%22%3E%40Pavel_Office%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDid%20you%20add%20the%20Microsoft.Office.Interop.Excel%20library%20to%20your%20project%20references%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1411604%22%20slang%3D%22en-US%22%3ERe%3A%20Combo%20box%20programming%20with%20c%23%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1411604%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F232473%22%20target%3D%22_blank%22%3E%40erol%20sinan%20zorlu%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20at%20the%20beginning%20of%20the%20program%20is%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3Eusing%20Microsoft.Office.Interop.Excel%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3Eusing%20System.IO%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EThe%20last%20command%20executed%20successfully%20is%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3Evar%20_contrl%20%3D%20wShtFrm.Shapes.Range%5B%22Drop%20Down%201%22%5D%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3ECommand%3C%2FP%3E%3CP%3E%3CSTRONG%3E_contrl.ListFillRange%20%3D%20%24%22List!%24C%242%3A%24C%24%7BiLast%7D%22%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ethrows%20this%20error%20message%3A%3C%2FP%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22119%22%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Pavel_Office935_0-1590152928320.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193887iDBB3E30A1B9B66EA%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Pavel_Office935_0-1590152928320.png%22%20alt%3D%22Pavel_Office935_0-1590152928320.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(System._ComObject%20does%20not%20contain%20a%20definition%20for%20ListFillRange)%3C%2FP%3E%3CP%3EThe%20recorded%20Excel%20macro%20is%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%20ActiveSheet.Shapes.Range(Array(%22Drop%20Down%201%22)).Select%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%20With%20Selection%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.ListFillRange%20%3D%20%22List!%24C%242%3A%24C%245%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.LinkedCell%20%3D%20%22C4%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.DropDownLines%20%3D%208%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Display3DShading%20%3D%20False%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%20End%20With%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1411709%22%20slang%3D%22en-US%22%3ERe%3A%20Combo%20box%20programming%20with%20c%23%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1411709%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F676902%22%20target%3D%22_blank%22%3E%40Pavel_Office935%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhen%20I%20check%20the%20both%20codes%20given%2C%20in%20VBA%20you%20%22select%22%20the%20shape%20and%20use%20FillListRange%20method%20of%20selection%20object.%20In%20the%20C%23%20version%20you%20create%20a%20var%20_cntrl%20and%20try%20to%20call%20this%20objects%20FillListRange%20method%20which%20simply%20doesn't%20exists%20as%20the%20variant%20object%20is%20a%20%22shape%22%20object.%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20fact%20when%20I%20try%20to%20assign%20the%20shape%20object%20to%20a%20VBA%20Shape%20variable%2C%20the%20FillListRange%20method%20doesn't%20exists%20also.%3C%2FP%3E%3CP%3EThe%20easiest%20way%20is%20to%20do%20the%20same%20in%20C%23%20and%20select%20the%20shape%20and%20use%20FillListRange%20method%20of%20the%20selection.%20However%26nbsp%3Bit%20is%20better%20to%20use%20the%20%22ActiveX%20ComboBox%22%20item%2C%20not%20the%20standard%20combobox%2C%20as%20this%20item%20has%20an%20object%20property%20which%20has%20a%20ListFillRange%20method.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1412117%22%20slang%3D%22en-US%22%3ERe%3A%20Combo%20box%20programming%20with%20c%23%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1412117%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F232473%22%20target%3D%22_blank%22%3E%40erol%20sinan%20zorlu%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%20it's%20already%20working!%3C%2FP%3E%3CP%3ESo%20the%20correct%20translation%20from%20VBA%20to%20C%23%20is%3A%3C%2FP%3E%3CP%3EShtFrm.Shapes.Range%5B%22Drop%20Down%201%22%5D.Select()%3B%3C%2FP%3E%3CP%3EexApl.Selection.ListFillRange%20%3D%20%24%22List!%24C%242%3A%24C%24%7BiLast%20%7D%22%3B%3C%2FP%3E%3CP%3EexApl.Selection.LinkedCell%20%3D%20%22C4%22%3B%3C%2FP%3E%3CP%3EexApl.Selection.DropDownLines%20%3D%204%3B%3C%2FP%3E%3CP%3EexApl.Selection.Display3DShading%20%3D%20false%3B%3C%2FP%3E%3CP%3EIt%20is%20actually%20simple.%3C%2FP%3E%3CP%3EI%20thought%20that%20when%20the%20application%20is%20running%20as%20Visible%20%3D%20false%20%2CI%20should%20not%20use%20the%20command%20Select()%3C%2FP%3E%3CP%3EThank%20you%20again!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Can someone can advise me how to programmatically set up a form control? I'll explain the problem on the example. My program opens a table Template.xlsx, completes the list of contact points, and saves it as a Form.xlsx. The end user should add a name to the Form.xlsx and select one point of contact. He uses a combo box control. When selects a contact point, their index is saved in cell C4, and the relevant cells show the street, city, zip code.

Form2.GIF

 

 

List1.GIF

Program written in C#, populates the contact table with the current values, and insetrs the current formula values. I can't program the combo box control.

The macro record for setting up the combo box is:

   ActiveSheet.Shapes.Range(Array("Drop Down 1")).Select

   Application.CutCopyMode = False

   With Selection

       .ListFillRange = "List!$C$2:$C$5"

       .LinkedCell = "C4"

       .DropDownLines = 8

       .Display3DShading = False

   End With

I don't know how to write this sequence in C#.

       private void CreateForm()

       {

           string templatePath = @"c:\Work\Template.xlsx";

           string formPath = @"c:\Work\Form.xlsx";

           if (File.Exists(formPath))

               File.Delete(formPath);

           var exApl = new Microsoft.Office.Interop.Excel.Application { Visible = false };

           var wBook = exApl.Workbooks.Open(templatePath);

           var wShtFrm = wBook.Worksheets["Form"];

           var wShtLst = wBook.Worksheets["List"];

           int iLast = 5;

           for (int i = 2; i <= iLast; i++)

           {

               wShtLst.Cells[i, 1] = "CP" + i;

               wShtLst.Cells[i, 2] = "Street " + i;

                wShtLst.Cells[i, 3] = "City " + i;

               wShtLst.Cells[i, 4] = 12300 + i;

           }

           wShtFrm.Range["B3"].FormulaR1C1Local = $"=INDEX(List!R2C1:R{iLast}C4;R4C3;1)";

           wShtFrm.Range["B4"].FormulaR1C1Local = $"=INDEX(List!R2C1:R{iLast}C4;R4C3;2)";

           wShtFrm.Range["B5"].FormulaR1C1Local = $"=INDEX(List!R2C1:R{iLast}C4;R4C3;3)";

           wShtFrm.Range["B6"].FormulaR1C1Local = $"=INDEX(List!R2C1:R{iLast}C4;R4C3;4)";

//=====================================================================

 

           var _contrl = wShtFrm.Shapes.Range["Drop Down 1"];

           //??????????

           //_contrl.ListFillRange = $"List!$C$2:$C${iLast }";

           //_contrl.LinkedCell = "C4";

           //_contrl.DropDownLines = 4;

           //_contrl.Display3DShading = false;

//=====================================================================

 

           wShtFrm.Protect(Contents: true);

           wShtFrm.EnableSelection = XlEnableSelection.xlUnlockedCells;

           wShtLst.Protect(Contents: true);

           wShtLst.EnableSelection = XlEnableSelection.xlUnlockedCells;

           wBook.Close(true, formPath);

           exApl.Quit();

       }

 

 

 

4 Replies

@Pavel_Office 

Did you add the Microsoft.Office.Interop.Excel library to your project references?

@erol sinan zorlu 

Yes, at the beginning of the program is:

using Microsoft.Office.Interop.Excel;

using System.IO;

The last command executed successfully is:

var _contrl = wShtFrm.Shapes.Range["Drop Down 1"];

Command

_contrl.ListFillRange = $"List!$C$2:$C${iLast}";

throws this error message:

 
 Pavel_Office935_0-1590152928320.png

 

 

(System._ComObject does not contain a definition for ListFillRange)

The recorded Excel macro is:

   ActiveSheet.Shapes.Range(Array("Drop Down 1")).Select

   With Selection

       .ListFillRange = "List!$C$2:$C$5"

       .LinkedCell = "C4"

       .DropDownLines = 8

       .Display3DShading = False

   End With

 

 

@Pavel_Office935 

 

when I check the both codes given, in VBA you "select" the shape and use FillListRange method of selection object. In the C# version you create a var _cntrl and try to call this objects FillListRange method which simply doesn't exists as the variant object is a "shape" object. 

In fact when I try to assign the shape object to a VBA Shape variable, the FillListRange method doesn't exists also.

The easiest way is to do the same in C# and select the shape and use FillListRange method of the selection. However it is better to use the "ActiveX ComboBox" item, not the standard combobox, as this item has an object property which has a ListFillRange method.

@erol sinan zorlu 

Thank you, it's already working!

So the correct translation from VBA to C# is:

ShtFrm.Shapes.Range["Drop Down 1"].Select();

exApl.Selection.ListFillRange = $"List!$C$2:$C${iLast }";

exApl.Selection.LinkedCell = "C4";

exApl.Selection.DropDownLines = 4;

exApl.Selection.Display3DShading = false;

It is actually simple.

I thought that when the application is running as Visible = false ,I should not use the command Select()

Thank you again!