CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C++ Builder >  基础类

两列的ListBox如何使用??

楼主lxj1984()2006-07-02 01:47:30 在 C++ Builder / 基础类 提问

一个两列的ListBox,如何添加数据?如何取得第二列的数据?? 问题点数:100、回复次数:7Top

1 楼rainfall19831109(恩恩)回复于 2006-07-02 03:52:17 得分 0

那要看看那个ListBox的Item属性是个什么类型的数据(不一定Item就是那个属性,具体要看控件,反正意思就是指示Item的属性)  
   
  根据我推测,应该是个TStringList类型的数据(也可能是控件定义的类型)  
  如果是TStringList的话,添加数据就直接给对应的Item调用TStringList的Add方法添加  
  读的时候就调用对应Item的Strings[Index]取数据Top

2 楼cbdxl(JF)回复于 2006-07-02 04:07:48 得分 0

楼主辛苦了!Top

3 楼lxj1984()回复于 2006-07-02 10:27:04 得分 0

谢谢,第一列的读写我会,可是第二列的,我就不知道了,不知道如何定位到第二列...Top

4 楼weixing979(★★★闪电侠★★★)回复于 2006-07-02 13:52:42 得分 20

两列的ListBox,是ListView吧.  
  如果是ListView  
   
   
  读写数据  
   
   
  void   __fastcall   TForm1::Button1Click(TObject   *Sender)  
  {  
      //写数据  
      TListItem   *   addItem   ;  
      addItem   =   ListView1->Items->Add();  
      addItem->Caption   =   "caption";  
      addItem->SubItems->Add("sub1");  
      addItem->SubItems->Add("sub2");  
   
      //读数据  
      Edit1->Text   =   ListView1->Items->Item[0]->Caption;  
      Edit2->Text   =   ListView1->Items->Item[0]->SubItems->Strings[0];  
      Edit3->Text   =   ListView1->Items->Item[0]->SubItems->Strings[1];  
   
  }Top

5 楼lother(阿艺)回复于 2006-07-02 13:58:53 得分 0

同意楼上Top

6 楼daydayup234(关中刀客)回复于 2006-07-03 10:29:54 得分 10

__fastcall   TForm1::TForm1(TComponent*   Owner):TForm(Owner)  
                  {  
                          ListView1->ViewStyle=vsReport;  
                          ListView1->Columns->Add();  
                          ListView1->Columns->Add();  
                          ListView1->Columns->Add();  
                          ListView1->Columns->Items[0]->Caption="主列";  
                          ListView1->Columns->Items[1]->Caption="子列1";  
                          ListView1->Columns->Items[2]->Caption="子列2";  
                  }  
                  //---------------------------------------------------------------------------  
                  void   __fastcall   TForm1::Button1Click(TObject   *Sender)   //添加数据  
                  {  
                          ListView1->Clear();  
   
                          TListItem*   theItem;  
                          //以下添加主列  
                          theItem=ListView1->Items->Add();  
                          theItem->Caption="one";  
                          //以下添加“子列   ”相当你说   第2列   与   主列添加   不同  
                          theItem->SubItems->Add("one的   子1");  
   
                          //再添加  
                          theItem=ListView1->Items->Add();  
                          theItem->Caption="two";  
                          theItem->SubItems->Add("two的   子1");  
                          theItem->SubItems->Add("two的   子2");  
                  }  
                  //---------------------------------------------------------------------------  
                  void   __fastcall   TForm1::Button2Click(TObject   *Sender)//取“第二列的数据”  
                  {  
                          TListItem*item;  
                          item=ListView1->Items->Item[1];   //第二行   注意   ListView1的Items从0算起  
                          AnsiString   s;  
                          s=item->SubItems->Strings[0];  
                          //注意     “第二列的数据”是   子列     的第一个,但是它从0算起       所以   ->Strings[0]  
                          ShowMessage(s);  
                  }  
                  //---------------------------------------------------------------------------  
  Top

7 楼BlueDeepOcean(蓝色·深海)回复于 2006-07-04 00:34:09 得分 70

楼上的,楼主说的是ListBox,而不是ListView。  
  看看我的代码:比如获得第二列:  
   
  void   __fastcall   TForm1::Button1Click(TObject   *Sender)  
  {  
                  int   rpc   =   ListBox1->ClientHeight   /   ListBox1->ItemHeight;  
                  int   col   =   ListBox1->Items->Count   /   rpc;  
   
                  if   (col   !=   ListBox1->Columns)  
                  {  
                                  if   (col   <   ListBox1->Columns)  
                                                  for   (int   idx   =   0;idx   <   rpc;idx   ++)  
                                                                  ShowMessage(ListBox1->Items->Strings[idx   +   rpc]);  
   
                                  if   (col   >   ListBox1->Columns   &&   ListBox1->Columns   !=   0)  
                                  {  
                                                  rpc   =   ListBox1->ClientHeight   /   ListBox1->ItemHeight;  
                                                  col   =   ListBox1->Items->Count   /   rpc;  
                                                  for   (int   idx   =   0;idx   <   rpc;idx   ++)  
                                                                  ShowMessage(ListBox1->Items->Strings[idx   +   rpc]);  
                                  }  
                  }  
                  else  
                                  for   (int   idx   =   0;idx   <   rpc;idx   ++)  
                                                                  ShowMessage(ListBox1->Items->Strings[idx   +   rpc]);  
  }  
  //---------------------------------------------------------------------------Top

相关问题

关键词

得分解答快速导航

  • 帖主:lxj1984
  • weixing979
  • daydayup234
  • BlueDeepOcean

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo