雖然從NullReferenceException異常的答案是一個不錯的開端,我沒有看到提及真正能夠幫助你尊重綁定的ID。我將使用的組合框的屬性是
RowSource = "tableNameThatHasTheRecords"
&& Dropdown list only allows those values in the table as valid
&& Dropdown COMBO allows the list OR manually entered values, but you have to deal with what if the entered value is not in the table... add it or what.
Style = 2 && List
Style = 0 && Combo
&& Fields. You want to display values from the columns in your table
RowSourceType = 6
&& Columns in the order you want displayed. However, if dealing with an "ID" Column that you don't necessarily want to show the user, this would typically be put LAST in the list of columns presented
RowSource = "ColumnX, ColumnY, IDColumn"
&& ColumnWidths is how wide you want each column when the drop-down is exposed. The first column is always shown in the combobox, but when in drop-down mode, will show all 3 columns possible, but since this example has the third column width of 0, it will NOT actually show the column value. (such as internal auto-increment ID that would otherwise mean nothing to the end-user).
ColumnWidths = "160, 85, 0"
&& How many columns in the row source that you have specifically made available
ColumnCount = 3
&& BOUND COLUMN is the key one for you. Which column of the row source do you want the value returned to the control's ".Value". In this case, column 3, the ID column even though the display width is zero, it will still put the ID as the selected value
BoundColumn = 3
我不明白如何打開數據庫?我應該在哪裏放置代碼? – Reynan
打開數據庫數據庫名,並使用像USE表名的表名,並檢查這個綁定http://stackoverflow.com/questions/9827957/foxpro-databinding-how-to-se-the-controlsource-and-the-display-source -properti?rq = 1 – NullReferenceException
這是最好的tutorial.go通過它 –
NullReferenceException