CListCtrl* theCtrl = GetListCtrl();
theCtrl.InsertColumn(0,"姓名",LVCFMT_CENTER,50);
theCtrl.InsertColumn(0,"班级",LVCFMT_CENTER,50);
如何将 “张三”加入到姓名列中;如何将“初三四班”加入到班级列中?

 

theCtrl.InsertItem(0, "张三");
第一个参数是索引即行数,写0就是插到第一行,第二个参数是内容

theCtrl.SetItemText(0, 1, "初三四班");
第一个参数同样是行索引,第二个参数是列索引,第三个不说了

首先使用theCtrl.GetItemCount();获得列表中的总行数。比如n=theCtrl.GetItemCount();
然后使用theCtrl.InsertItem(n, "张三");新加一行,但新增的行只有第一列有数据,就是"张三",后面的列就可以用theCtrl.SetItemText(n, 1, "初二六班");的方法进行设置或修改了。
当然不用获得总行数,直接用theCtrl.InsertItem(0, "张三");会把新行插到第一行的位置,类似于头插法,上面说的那个相当于尾插法。

 

注:如果出现:error C2228: left of '.InsertItem' must have class/struct/union type Error executing cl.exe.错误

那么把theCtrl.GetItemCount();改成theCtrl->GetItemCount();即可

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-08-31
  • 2022-12-23
  • 2021-05-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-11-02
相关资源
相似解决方案