** END HEADER -- do not remove this line // // Generated on 03/09/2024 // parameter bModal local f f = new Charlie_ComboboxForm() if (bModal) f.mdi = false // ensure not MDI f.readModal() else f.open() endif class Charlie_ComboboxForm of FORM with (this) scaleFontName = "Calibri" scaleFontSize = 12.0 height = 16.0 left = 73.5 top = 6.52 width = 40.0 text = "" endwith this.CHARLIENAMES1 = new QUERY(this) with (this.CHARLIENAMES1) left = 4.0 top = 11.0 width = 9.0 height = 1.0 sql = 'select * from "CharlieNames.dbf"' active = true endwith with (this.CHARLIENAMES1.rowset) indexName = "NAME" endwith this.TEXT1 = new TEXT(this) with (this.TEXT1) height = 1.0 left = 2.125 top = 0.88 width = 28.25 fontName = "Calibri" fontSize = 12.0 text = "Combobox Example for Charlie" endwith this.TEXT2 = new TEXT(this) with (this.TEXT2) height = 1.0 left = 2.5 top = 3.44 width = 6.75 fontName = "Calibri" fontSize = 12.0 text = "Name:" endwith this.COMBOBOX1 = new COMBOBOX(this) with (this.COMBOBOX1) onChange = class::COMBOBOX1_ONCHANGE height = 1.0 left = 2.25 top = 4.68 width = 29.625 fontName = "Calibri" fontSize = 12.0 dataSource = form.charlienames1.rowset.fields["name"] style = 1 // DropDown endwith this.ENTRYFIELD1 = new ENTRYFIELD(this) with (this.ENTRYFIELD1) height = 1.0 left = 3.375 top = 7.16 width = 27.0 fontName = "Calibri" fontSize = 12.0 value = "Another control to get focus" maxLength = 28 endwith this.rowset = this.charlienames1.rowset function COMBOBOX1_onChange() // fires when leaving the combobox ... private r, f, cName, bFound // shortcuts r = form.rowset f = r.fields cName = this.value // combobox value // navigate to first row: r.first() bFound = false do while not r.endOfSet // loop to end if cName.toUpperCase().rightTrim().leftTrim() == ; f["Name"].value.toUpperCase().rightTrim().leftTrim() bFound := true exit // no need to continue looking endif r.next() // next row enddo if not bFound if msgbox( "Do you want to add this name to the table?", ; "Name not found!", 36 ) == 6 // add a new record: r.beginAppend() // add the name: f["Name"].value := cName // save it: r.save() // now re-load the datasource: this.dataSource := this.dataSource endif // msgbox endif // not bFound return endclass