将列表框属性外观中的View设置为Report
1.初始化列表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
//初始化List
m_list.SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_ONECLICKACTIVATE|LVS_EX_GRIDLINES);
//
RECT rect;
//
m_list.GetClientRect(&rect);
//
int
width=rect.right-rect.left;
m_list.InsertColumn(0,_T(
"商品编号"
),LVCFMT_LEFT,70);
m_list.InsertColumn(1,_T(
"商品名称"
)"
m_list.InsertColumn(2,_T(
"商品规格"
)"
m_list.InsertColumn(3,_T(
"商品进价"
)"
m_list.InsertColumn(4,_T(
"商品售价"
)"
m_list.InsertColumn(5,_T(
"商品数量"
)"
m_list.DeleteAllItems();
//
for
(
int
k=0;k<6;k++)
//
{
//
m_list.SetColumnWidth(k,width/6);
//
}
|
2.向列表中插入数据
1
2
3
4
5
6
7
8
9
10
11
12
|
int
item=m_list.InsertItem(0,
""
);
CString tes;
tes.Format(
"%d"
,id);
m_list.SetItemText(item,0,tes);
m_list.SetItemText(item,1,mercname);
m_list.SetItemText(item,2,mercspec);
tes.Format(
"%.2f"
,inprice);
m_list.SetItemText(item,3,tes);
tes.Format(
"%.2f"
,outprice);
m_list.SetItemText(item,4,tes);
tes.Format(
"%d"
,mynum);
m_list.SetItemText(item,5,tes);
|
3.删除列表中指定行的数据
//如果被选中
if
(m_list.GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED)
{
SqlHelper *sqlhelper=
new
SqlHelper();
int
id=
atoi
(m_list.GetItemText(i,0));
UpdateData(TRUE);
int
storid=m_storid;
CString sql;
sql.Format(
"delete from tb_storelist where storid=%d and mercid=%d"
,storid,id);
if
(sqlhelper->mydelete(sql))
{
sql.Format(
"delete from tb_merc where id=%d"
,id);
if
(sqlhelper->mydelete(sql))
{
MessageBox(
"删除成功"
,
"提示"
);
}
m_list.DeleteItem(i);
}
delete
sqlhelper;
}
//删除列表中选中的项
POSITION pos = m_list.GetFirstSelectedItemPosition();
while(pos)
{
int index = m_list.GetNextSelectedItem(pos);
m_list.DeleteItem(index);
}
POSITION pos = m_list.GetFirstSelectedItemPosition();
while(pos)
{
int index = m_list.GetNextSelectedItem(pos);
m_list.DeleteItem(index);
}