2017-01-10 90 views
1

我有2個表:簡單顯示方法

Table: country1 - fields: CountryId ,CountryName 
Table: City1 - fields: CityId, CityName, CountryId 

有通過CountryId 2和表之間的關係,每個城市都有一個Country id並且存在與單個數據源City1 和網格字段CityId,CityName, CountryId 一個形式我需要在
design-designs-grid-methods-new方法

display CountryName method1(City1 cit) 
{ 
    Country1 c1; 
    select CountryName from c1 
     where c1.CountryId == cit.CountryId; 
    return c1.CountryName; 
} 
創建了一個新方法網格顯示的 CountryName代替

但當形式打開ID仍顯示爲一個ID不是CountryName

回答

0

移動你的顯示方法的形式的數據源。從網格中刪除countryid字段,並將顯示方法拖放爲網格字段。 推薦的方法是在表City1中添加顯示方法。爲此需要修改您現有的顯示方法以使用表緩衝區。

+0

請不要建議在沒有上下文的表單上創建顯示方法,它們不可重用,並且性能可怕。 –

1

如果可能的話,力爭新增display methods到它所屬的表,在這種情況下City1:上表

display CountryName contryName() 
{ 
    return (select firstOnly CountryName from Country1 
       where Country1.CountryId == this.CountryId).CountryName; 
} 

顯示方法不帶任何參數,使用this關鍵字。
爲避免出現多餘變量,您可以使用,如此處所示使用內嵌select expression
將顯示方法從表格拖到表單容器控件後,請記住在生成的控件上設置Datasource屬性。

相關問題