本帖最后由 W9757 于 2010-11-24 16:14:39 编辑

解决方案 »

  1.   

    Two master-detail relationships must be set up.  The first one is between the master FILMS and detail STAFF tables.  The second one is between the master FILMS and detail FILMSSCREENS tables.
    1. For the first relationship, you need to adjust the properties of the tvStaff View.  Open the Object Inspector and set the attributes as follows:?DataController.DetailKeyFieldNames to FILMID?DataController.KeyFieldNames to ID?DataController.MasterkeyFieldNames to IDDetailKeyFieldNames specifies the field(s) from the detail tvStaff View.  The MasterkeyFieldNames property specifies the field(s) from the master tvFilms View.  Detail key fields must correspond to master key fields.  The KeyFieldNames property specifies the field(s) in the detail View uniquely identifying each record.  Refer to its description for more information.
    可以看一下帮助。红色字体很重要。
      

  2.   

    真是笨的要命,问题出在cxGrid1Level上。就你一个人回我,分就给你吧。
      

  3.   

    设置cxgrid的主从表很简单,只需要设置好
    从表DBtableView2的keyfieldnames,DetailKeyFieldNames和MasterKeyFieldNames 就行啦,
    MasterKeyFieldNames为主表关联字段,
    DetailKeyFieldNames 为从表关联字段,
    keyfieldnames设置就是关键,这里应该设置的是从表主键字段,而不是网上很多说的跟MasterKeyFieldNames字段一样.  
    主表DBtableView1的keyfieldnames可以不用设置.至于为什么 从表焦点只有第一条记录,不能移动呢?
    是因为从表的keyfieldnames设置不对.keyfieldnames的作用是指定从表查找记录的字段,
    当设置的与MasterKeyFieldNames字段一样时,从表该字段的值都是一样的,当表查找记录时,按该字段查找,只找到第一条记录,就认为找到记录了,所以出现从表焦点只有第一条记录,不能移动的情况.
    故 从表的keyfieldnames要设置为能唯一确定从表一行记录的字段,这一般为从表主键字段,当然从表某一字段不是主键,但能唯一确定从表一行记录的字段也行.
      

  4.   

    对楼上的补充:
    最好在DataSet的indexFieldName处设置唯一字段名称 
    例如:AClientDataSet.IndexFieldName:= 'ID';