我想在一个form1中实现信息浏览的功能,当通过form2添加完相应信息后,在form1中的listview中用相应状态的图标和文字同时显示出来,例如,在form2中添加Nokia手机信息,则在form1的listview第一行的第一列中显示手机的图标,同时图标下面注释有“Nokia手机”字样;再添加飞利浦手机的手机的信息,则在第一行的第二列显示手机的图标,同时图标下面注释有“飞利浦手机”字样;再添加mp4的信息,则在第一行第三列显示mp4的图标,同时图标下面注释有“mp4”字样,…………依次类推,从而实现信息浏览的功能。同时能实现按“注释名称排序”的功能。
    图标在一个文件夹中,但如何添加并实现,请大侠帮忙,谢谢大家了,最好能给出delphi源代码,

解决方案 »

  1.   

    给个思路将添加的信息的的名称跟图表存到数据库
    listview从数据库中读
    添加完一条
    刷新一次listview
      

  2.   

    不用LISTVIEW用LISTBOX就可以(代码网上找的)procedure TForm1.FormCreate(Sender: TObject);
    var
       i: integer; 
    begin 
       lsbRight.Style := lbOwnerDrawFixed; 
       lsbRight.Ctl3D := false;
       lsbRight.ItemHeight := 50;
       lsbRight.Items.Add('C++ Builder 研究 致力于BCB的学习探讨和研究'#13'ccrun(老妖)'); 
       lsbRight.Items.Add('编程手札 My Developer Knowledge Base'#13'http://blog.csdn.net/nhconch'#13'天蝎蝴蝶'); 
       for i:=3 to 10 do begin 
           lsbRight.Items.Add('ListBox Items of ' + IntTostr(i) + #13'Second of ' 
               + IntToStr(i) + #13'Third of ' + IntToStr(i));
       end;    lsbLeft.Style := lbOwnerDrawFixed; 
       lsbLeft.Ctl3D := false; 
       lsbLeft.ItemHeight := 90; 
       lsbLeft.Items.Add('编程手札'); 
       lsbLeft.Items.Add('My Developer Knowledge Base'); 
       lsbLeft.Items.Add('站长:天蝎蝴蝶');
       lsbLeft.Items.Add('http://blog.csdn.net/nhconch'); 
    end;
    procedure TForm1.lsbRightDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
       strTemp: String; 
    begin 
       //文字颜色
       lsbRight.Canvas.Font.Color := clBlack; 
       //设置背景颜色并填充背景 
       lsbRight.Canvas.Brush.Color := clWhite; 
       lsbRight.Canvas.FillRect (Rect);
       //设置圆角矩形颜色并画出圆角矩形
       lsbRight.Canvas.Brush.Color := TColor({row.content}$FFF7F7);
       lsbRight.Canvas.Pen.Color := TColor({row.content}131315);
       lsbRight.Canvas.RoundRect(Rect.Left + 3, Rect.Top + 3,
               Rect.Right - 2, Rect.Bottom - 2, 8, 8);
       //以不同的宽度和高度再画一次,实现立体效果
       lsbRight.Canvas.RoundRect(Rect.Left + 3, Rect.Top + 3,
               Rect.Right - 3, Rect.Bottom - 3, 5, 5);
       //如果是当前选中项
       if(odSelected in State) then
       begin
           //以不同的背景色画出选中项的圆角矩形
           lsbRight.Canvas.Brush.Color := TColor({row.content}$FFB2B5);
           lsbRight.Canvas.RoundRect(Rect.Left + 3, Rect.Top + 3, 
                   Rect.Right - 3, Rect.Bottom - 3, 5, 5);
           //选中项的文字颜色
           lsbRight.Canvas.Font.Color := clBlue; 
           //如果当前项拥有焦点,画焦点虚框,当系统再绘制时变成XOR运算从而达到擦除焦点虚框的目的 
           if(odFocused in State) then DrawFocusRect(lsbRight.Canvas.Handle, Rect); 
       end; 
       //画出图标 
       ImageList1.Draw(lsbRight.Canvas, Rect.Left + 7, 
               Rect.top + (lsbRight.ItemHeight - ImageList1.Height) div 2, Index, true); 
       //分别绘出三行文字 
       strTemp := lsbRight.Items.Strings[Index]; 
       lsbRight.Canvas.TextOut(Rect.Left + 32 + 10, Rect.Top + 4 
                               , Copy(strTemp, 1, Pos(#13, strTemp)-1)); 
       strTemp := Copy(strTemp, Pos(#13, strTemp)+1, Length(strTemp));
       lsbRight.Canvas.TextOut(Rect.Left + 32 + 10, Rect.Top + 18, 
                               Copy(strTemp, 1, Pos(#13, strTemp)-1)); 
       lsbRight.Canvas.TextOut(Rect.Left + 32 + 10, Rect.Top + 32, 
                               Copy(strTemp, Pos(#13, strTemp)+1, Length(strTemp))); 
    end; 
    procedure TForm1.lsbRightClick(Sender: TObject);
    begin
      StaticText1.Caption := ' ' + lsbRight.Items.Strings[lsbRight.ItemIndex];
    end;procedure TForm1.FormShow(Sender: TObject);
    begin
      lsbRight.ItemIndex := 0;
      lsbRight.Repaint();  lsbLeft.ItemIndex := 0;
      lsbLeft.Repaint();
    end;procedure TForm1.lsbLeftDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
       r: TRect; 
    begin 
       with lsbLeft.Canvas do begin
           //设置填充的背景颜色并填充背景
           Brush.Color := clWhite;
           FillRect (Rect);
           //绘制圆角矩形
           if (odSelected in State) then   //选中项的圆角矩形颜色
               Pen.Color := $FFB2B5 
           else                            //未选中项的圆角矩形颜色 
               Pen.Color := clSilver;
           Brush.Style := bsClear; 
           SetRect(r, Rect.Left+3, Rect.Top+3, Rect.Right-3, Rect.Bottom-3); 
           RoundRect(r.Left, r.Top, r.Right, r.Bottom, 10, 10);
           //画出图标
           if (odSelected in State) then   //选中项的图像 
               Draw(r.Left + (r.Right - r.Left - imgHouse.Width) shr 1,
                   r.Top + 2, imgHouse.Picture.Graphic) 
           else                            //未选中项的图像 
               Draw(r.Left + (r.Right - r.Left - imgHouseGray.Width) shr 1, 
                   r.Top + 2, imgHouseGray.Picture.Graphic);
           //填充文字区背景
           r.Top := r.Bottom - Abs(Font.Height) - 4;
           Brush.Style := bsSolid;
           if (odSelected in State) then   //选中项的背景颜色 
               Brush.Color := $FFB2B5 
           else                            //未选中项的背景颜色
               Brush.Color := clSilver; 
           FillRect(r); 
           //输出文字,仅支持单行 
           Font.Color := clBlack; 
           r.Top := r.Top + 2; //计算文字顶点位置,(水平居中,DT_CENTER不可用) 
           DrawText(Handle, PChar(TListBox(Control).Items.Strings[Index]), -1, r 
                   , DT_CENTER or DT_END_ELLIPSIS{ or DT_WORDBREAK}); 
           //画焦点虚框,当系统再绘制时,变成XOR运算,从而达到擦除焦点虚框的目的 
           if(odFocused in State) then DrawFocusRect(Rect); 
    end;
    end;
      

  3.   

    lsbRight: TListBox;
        lsbLeft: TListBox;
        ImageList1: TImageList;
        StaticText1: TStaticText;
        imgHouse: TImage; //用于选中该项后彩色显示该项图标
        imgHouseGray: TImage; //未选中的灰色显示该项图标
      

  4.   

    二楼andyzhou1101:
    你说的保存到数据库中,然后用listview读取,我知道这样可以,但关键是如何读取,怎样书写代码?
      

  5.   

    二楼andyzhou1101:
    你说的保存到数据库中,然后用listview读取,我知道这样可以,但关键是如何读取,怎样书写代码?-----------------------------------------将listview跟数据库结合起来啊
    去盒子上下个listview的例子好好看看
    :)