串口通信中CListCtrl

jiejie1979 2007-04-13 02:51:23
我做的串口通信,我想在没有接收到数据时让CListCtrl中每个格都显示"//",当接收到数据时替换掉,下面是我在初始化时写的代码,可是运行时只有第一行都显示'//',其它的都没有显示"//"? 还有当来数据时我怎么让数据替换掉'//'? 我刚学VC++,希望有会的把代码帮我改一下,马上给分
int nCount = m_hListMinuteData.GetItemCount(); //获取项目的总数,插入行
int row = m_hListMinuteData.InsertItem( nCount, "//" ); //InsertItem用于向列表控件插入一行并设置第零列的值
m_hListMinuteData.SetItemText(row,1,"//");//SetItemText来设置其它列的数据。
m_hListMinuteData.SetItemText(row,2,"//");
m_hListMinuteData.SetItemText(row,3,"//");
m_hListMinuteData.SetItemText(row,4,"//");
m_hListMinuteData.SetItemText(row,5,"//");
m_hListMinuteData.SetItemText(row,6,"//");
m_hListMinuteData.SetItemText(row,7,"//");
m_hListMinuteData.SetItemText(row,8,"//");

m_hListMinuteData.InsertColumn(1,"//",LVCFMT_LEFT,nCount);//插入列
m_hListMinuteData.InsertColumn(2,"//",LVCFMT_LEFT,nCount);
m_hListMinuteData.InsertColumn(3,"//",LVCFMT_LEFT,nCount);
m_hListMinuteData.InsertColumn(4,"//",LVCFMT_LEFT,nCount);
m_hListMinuteData.InsertColumn(5,"//",LVCFMT_LEFT,nCount);
m_hListMinuteData.InsertColumn(6,"//",LVCFMT_LEFT,nCount);
m_hListMinuteData.InsertColumn(7,"//",LVCFMT_LEFT,nCount);
m_hListMinuteData.InsertColumn(8,"//",LVCFMT_LEFT,nCount);
m_hListMinuteData.SetItemData(row,nCount);
...全文
149 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiejie1979 2007-04-13
  • 打赏
  • 举报
回复
lfchen(一条晚起的虫--床上用品[家纺]专卖)
谢谢,我试一下,我加你为好友吧,不会好问你,把分给你吧
一条晚起的虫 2007-04-13
  • 打赏
  • 举报
回复
//要先插入列,
m_hListMinuteData.InsertColumn(0,"列名",LVCFMT_LEFT,宽度);//插入列
....
m_hListMinuteData.InsertColumn(9,"列名",LVCFMT_LEFT,宽度);//10列插完


//插入行
//*************
int row = m_hListMinuteData.InsertItem(0, "//" ); //插入行,并给第一列赋值
//设置每列的显示
m_hListMinuteData.SetItemText(row, 1, "//");
.....
m_hListMinuteData.SetItemText(row, 9, "//"); //第十列赋值
//***********
//继续插入行,需要多少行重复多少次

//修改
m_hListMinuteData.SetItemText(2, 1, "aa"); //设置第3行第2列的值

//注意:列、行的下标从0还是从1开始,不记得了
jiejie1979 2007-04-13
  • 打赏
  • 举报
回复
mochen5460(mochen)
不得用一个语句吗,象你说的那样做了,可是数据都显示到下一行了,没替换呀
用不用Replace?我好象在哪看见过,不过没用过呀
jiejie1979 2007-04-13
  • 打赏
  • 举报
回复
lfchen(一条晚起的虫--床上用品[家纺]专卖)
这个我也查了,可是我刚学,没写明白,你是说我写的顺序反了吗,会就麻烦你帮我改一下
jiejie1979 2007-04-13
  • 打赏
  • 举报
回复
mochen5460(mochen)
我怎么才能向其它的格都写入"//",希望能帮我改一下,我改了很长时间都不对呀
mochen5460 2007-04-13
  • 打赏
  • 举报
回复
m_hListMinuteData.SetItemText(row,2,"//");
-----------------------------------------
用你要显示的数据替换掉//就可以了
一条晚起的虫 2007-04-13
  • 打赏
  • 举报
回复
先插入列,然后插入行。
int InsertColumn(
int nCol,
LPCTSTR lpszColumnHeading,
int nFormat = LVCFMT_LEFT,
int nWidth = -1,
int nSubItem = -1
);

Parameters
nCol
The index of the new column.

lpszColumnHeading
Address of a string containing the column's heading.

nFormat
Integer specifying the alignment of the column. It can be one of these values: LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER.

nWidth
Width of the column, in pixels. If this parameter is -1, the column width is not set.

nSubItem
Index of the subitem associated with the column. If this parameter is -1, no subitem is associated with the column.

//替换
SetItemText就可以了。
jiejie1979 2007-04-13
  • 打赏
  • 举报
回复
CListCtrl列是固定的10列,有谁知道怎么改,并写出替换"//"的代码,非常感谢,希望能有高手帮助我.
mochen5460 2007-04-13
  • 打赏
  • 举报
回复
可是运行时只有第一行都显示'//',其它的都没有显示"//"
-------------------------------------------------------
楼主你只向第一行写入了啊,当然只有第一行显示


2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧