如何把一个表中的数据按如下的格式显示在2个LISTBOX中?
表:                          listbox1            listbox2
  A   1                        A                     1
  A   2                                              2
  A   3                                              3
  A   4                                              4
  B   2                        B                     2 
  B   4                                              4
  B   5                                              5
  C   3                        C                     3
  C   5                                              5

解决方案 »

  1.   

    假设
    select f1,f2 from tbl order by f1;
    var s:string;
    -------------------query1.first;
    listbox1.Clear;
    listbox2.Clear;
    while not query1.eof do
    begin
      if query1.fieldbyname('f1').asstring<>s then
        listbox1.Items.Add(query1.fieldbyname('f1').asstring)
      else
        listbox1.Items.Add('');
      s:=query1.fieldbyname('f1').asstring;
      listbox2.items.add(query1.fieldbyname('f2).asstring);
      query1.next;
    end;
      

  2.   

    表 table1
    id  name
    A    1
    A    2
    ……
    到listbox1,
    select id form table1 group by id
    listbox1.items.add(……
    到listbox2
    select name from table1 where id='A' listbox2.items.add(……);
    select name from table1 where id='B'
    ……