动态给dbgrid添加列后,只显示空行,有几行数据就有几行空行,哪里出问题了这是,谢谢!
DM.ADOshow_topic_patent.Active :=true ;
  dbgrid1.CleanupInstance;
  for i := 0 to DM.ADOtemplate.RecordCount  - 1 do    //把一个模板所有列添加在dbgrid
  begin
    column:=DBGrid1.Columns.Add ;
    Column.FieldName:=DM.ADOtemplate.FieldByName('template_field').AsWideString  ;
    end;
    DM.ADOtemplate.next;
  end;
  dbgrid1.Refresh;

解决方案 »

  1.   

    这样应该是不行的
    dbgrid必须有数据源,在有数据源的情况下只能新增一行如果想增加多行,就的给一行中的某个列赋值才行
      

  2.   

    看起代码没有问题,估计是动态设置的字段在DBGrid1连接的数据集中不存在。
      

  3.   

    CleanupInstanceDo not call CleanupInstance directly. CleanupInstance is called automatically when the object instance is destroyed.
    CleanupInstance releases all long strings and Variants. (It set long strings to empty and Variants to Unassigned.)括號內重點,估計是出在這里吧,呵呵,瞎蒙的哦
      

  4.   

    我实在看不出问题了,记录集也连了,也active了,CleanupInstance去掉也不行,我要双击dbgrid设好了列就能显示数据,这样动态添加列就不显示,高手们再给看看!!
      

  5.   

    DM.ADOshow_topic_patent.Active :=true ;
    DBGrid1.Columns.Clear;
    if DM.ADOtemplate.Active then
    begin
      for i := 0 to DM.ADOtemplate.RecordCount  - 1 do    //把一个模板所有列添加在dbgrid
      begin
        column:=DBGrid1.Columns.Add ;
        Column.FieldName:=DM.ADOtemplate.Fields.Fields[i].FieldName;    
         Column.Width:= 100;
        end;
        DM.ADOtemplate.next;
      end;
    end else
    begin
       showmessage('DM.ADOtemplate还未打开');
    end;
    你是不是数据集错了啊
      

  6.   

    数据集绝对打开了,就是行不通,我最后用另一种方法实现的,用for循环,把表中没有提到的字段隐藏(visible:=false)