mfc怎么向listctrl中添加一行数据
2个回答
推荐于2016-12-04
展开全部
看个例子
C/C++ code// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
CString strText;
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();
// Insert 10 items in the list view control.
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i);
// Insert the item, select every other item.
pmyListCtrl->InsertItem(
LVIF_TEXT|LVIF_STATE, i, strText,
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
0, 0);
// Initialize the text of the subitems.
for (int j=1;j < nColumnCount;j++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
pmyListCtrl->SetItemText(i, j, strText);
}
}
------解决方案--------------------
给你个例子。。。
m_list.InsertColumn(0,"Col 1");
m_list.InsertColumn(1,"Col 2");
m_list.InsertColumn(2,"Col 3");
m_list.InsertColumn(3,"Col 4");
m_list.InsertItem(0,"row1",0);
CString stemp ="";
for(int i =0;i<4;i++)
{
stemp.Format("row 0 %d",i);
m_list.SetItemText(0,i,stemp);
}
m_list.InsertItem(0,"row befor prev",0);
m_list.InsertItem(2,"row after prev",0);
注意InsertItem的第一个参数
结果因该是这样的
row befor prev
row1 row01 row02 row03 row04
row after prev
C/C++ code// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
CString strText;
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();
// Insert 10 items in the list view control.
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i);
// Insert the item, select every other item.
pmyListCtrl->InsertItem(
LVIF_TEXT|LVIF_STATE, i, strText,
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
0, 0);
// Initialize the text of the subitems.
for (int j=1;j < nColumnCount;j++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
pmyListCtrl->SetItemText(i, j, strText);
}
}
------解决方案--------------------
给你个例子。。。
m_list.InsertColumn(0,"Col 1");
m_list.InsertColumn(1,"Col 2");
m_list.InsertColumn(2,"Col 3");
m_list.InsertColumn(3,"Col 4");
m_list.InsertItem(0,"row1",0);
CString stemp ="";
for(int i =0;i<4;i++)
{
stemp.Format("row 0 %d",i);
m_list.SetItemText(0,i,stemp);
}
m_list.InsertItem(0,"row befor prev",0);
m_list.InsertItem(2,"row after prev",0);
注意InsertItem的第一个参数
结果因该是这样的
row befor prev
row1 row01 row02 row03 row04
row after prev
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看个例子
C/C++ code// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
CString strText;
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();
// Insert 10 items in the list view control.
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i);
// Insert the item, select every other item.
pmyListCtrl->InsertItem(
LVIF_TEXT|LVIF_STATE, i, strText,
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
0, 0);
// Initialize the text of the subitems.
for (int j=1;j < nColumnCount;j++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
pmyListCtrl->SetItemText(i, j, strText);
}
}
------解决方案--------------------
给你个例子。。。
m_list.InsertColumn(0,"Col 1");
m_list.InsertColumn(1,"Col 2");
m_list.InsertColumn(2,"Col 3");
m_list.InsertColumn(3,"Col 4");
m_list.InsertItem(0,"row1",0);
CString stemp ="";
for(int i =0;i<4;i++)
{
stemp.Format("row 0 %d",i);
m_list.SetItemText(0,i,stemp);
}
m_list.InsertItem(0,"row befor prev",0);
m_list.InsertItem(2,"row after prev",0);
注意InsertItem的第一个参数
结果因该是这样的
row befor prev
C/C++ code// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
CString strText;
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();
// Insert 10 items in the list view control.
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i);
// Insert the item, select every other item.
pmyListCtrl->InsertItem(
LVIF_TEXT|LVIF_STATE, i, strText,
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
0, 0);
// Initialize the text of the subitems.
for (int j=1;j < nColumnCount;j++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
pmyListCtrl->SetItemText(i, j, strText);
}
}
------解决方案--------------------
给你个例子。。。
m_list.InsertColumn(0,"Col 1");
m_list.InsertColumn(1,"Col 2");
m_list.InsertColumn(2,"Col 3");
m_list.InsertColumn(3,"Col 4");
m_list.InsertItem(0,"row1",0);
CString stemp ="";
for(int i =0;i<4;i++)
{
stemp.Format("row 0 %d",i);
m_list.SetItemText(0,i,stemp);
}
m_list.InsertItem(0,"row befor prev",0);
m_list.InsertItem(2,"row after prev",0);
注意InsertItem的第一个参数
结果因该是这样的
row befor prev
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询