用CListCtrl控件显示数据库信息
for(inti=0;i<m_userSet.GetRecordCount();i++){CStringtemp;m_userSet.GetFieldValue("use...
for(int i=0;i<m_userSet.GetRecordCount();i++)
{
CString temp;
m_userSet.GetFieldValue("user_id",temp);
m_list.InsertItem(i,temp);
m_userSet.GetFieldValue("user_name",temp);
m_list.SetItemText(i,1,temp);
m_userSet.GetFieldValue("user_password",temp);
m_list.SetItemText(i,2,temp);
m_userSet.GetFieldValue("user_level",temp);
m_list.SetItemText(i,3,temp);
m_userSet.MoveNext();
}
m_userSet 是记录集对象 m_list是CListCtrl对象 但是显示时只会出现几个数字 请高手指点
还有插入列的一些代码
m_list.InsertColumn(0,"用户编号");
m_list.InsertColumn(1,"用户名");
m_list.InsertColumn(2,"密码");
m_list.InsertColumn(3,"用户权限"); 展开
{
CString temp;
m_userSet.GetFieldValue("user_id",temp);
m_list.InsertItem(i,temp);
m_userSet.GetFieldValue("user_name",temp);
m_list.SetItemText(i,1,temp);
m_userSet.GetFieldValue("user_password",temp);
m_list.SetItemText(i,2,temp);
m_userSet.GetFieldValue("user_level",temp);
m_list.SetItemText(i,3,temp);
m_userSet.MoveNext();
}
m_userSet 是记录集对象 m_list是CListCtrl对象 但是显示时只会出现几个数字 请高手指点
还有插入列的一些代码
m_list.InsertColumn(0,"用户编号");
m_list.InsertColumn(1,"用户名");
m_list.InsertColumn(2,"密码");
m_list.InsertColumn(3,"用户权限"); 展开
1个回答
展开全部
好久没用VC了,看不出什么错,下面的代码是我以前写的,能正常使用,你以、可以参考一下
int CUserInfoDlg::InitList()
{
m_imlist.Create(16, 16, ILC_COLOR32, 1, 1);
//初始化左边列表:
DWORD dwStyle;
dwStyle = m_list_all.GetStyle();
dwStyle |= LVS_EX_FULLROWSELECT| LVS_SHOWSELALWAYS;
m_list_all.SetExtendedStyle(dwStyle);
//设置背景色
m_list_all.SetBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_all.SetTextBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_all.SetHoverTime(1000000);
//添加列
CString infoname = "ID";
LV_COLUMN lvc;
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT;
lvc.cx = 110;//长度
lvc.iSubItem = 0;
lvc.fmt &= ~LVCFMT_JUSTIFYMASK;
lvc.fmt |= LVCFMT_CENTER;//居中显示
lvc.pszText = infoname.GetBuffer(0);
if(-1 == m_list_all.InsertColumn(0, &lvc))
{
MessageBox("程序出错!");
}
//设置图标
m_list_all.SetImageList(&m_imlist, LVSIL_SMALL);
//初始化右边的
dwStyle = m_list_friend.GetStyle();
dwStyle |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT| LVS_SHOWSELALWAYS;
m_list_friend.SetExtendedStyle(dwStyle);
//设置背景色
m_list_friend.SetBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_friend.SetTextBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_friend.SetHoverTime(1000000);
//添加列
if(-1 == m_list_friend.InsertColumn(0, &lvc))
{
MessageBox("程序出错!");
}
//设置图标
m_list_friend.SetImageList(&m_imlist, LVSIL_SMALL);
return 0;
}
int CUserInfoDlg::InitData()
{
CUserArray alluser;
g_pdbReader->ShowAllUser(alluser);
int n = alluser.size();
//初始化图标
CString all_icon_path = ".\\icon\\icon";
CString the_icon_path = "";
for(int i = 0; i < MAXICON; i++)
{
the_icon_path.Format("%s_%d.ico", all_icon_path, i);
m_imlist.Add( HCH_LoadIcon(the_icon_path) );
}
CString buffer;
LVITEM lvitem;
lvitem.mask = LVIF_IMAGE | LVIF_TEXT;
lvitem.iSubItem = 0;
for (int j = 0; j < n; j++)
{
lvitem.iItem = j;
buffer.Format("%d", alluser[j].num);
lvitem.pszText = buffer.GetBuffer(0);
buffer.ReleaseBuffer();
lvitem.iImage = alluser[j].pic_serial;
m_list_all.InsertItem(&lvitem);
}
return 0;
}
int CUserInfoDlg::InitList()
{
m_imlist.Create(16, 16, ILC_COLOR32, 1, 1);
//初始化左边列表:
DWORD dwStyle;
dwStyle = m_list_all.GetStyle();
dwStyle |= LVS_EX_FULLROWSELECT| LVS_SHOWSELALWAYS;
m_list_all.SetExtendedStyle(dwStyle);
//设置背景色
m_list_all.SetBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_all.SetTextBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_all.SetHoverTime(1000000);
//添加列
CString infoname = "ID";
LV_COLUMN lvc;
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT;
lvc.cx = 110;//长度
lvc.iSubItem = 0;
lvc.fmt &= ~LVCFMT_JUSTIFYMASK;
lvc.fmt |= LVCFMT_CENTER;//居中显示
lvc.pszText = infoname.GetBuffer(0);
if(-1 == m_list_all.InsertColumn(0, &lvc))
{
MessageBox("程序出错!");
}
//设置图标
m_list_all.SetImageList(&m_imlist, LVSIL_SMALL);
//初始化右边的
dwStyle = m_list_friend.GetStyle();
dwStyle |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT| LVS_SHOWSELALWAYS;
m_list_friend.SetExtendedStyle(dwStyle);
//设置背景色
m_list_friend.SetBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_friend.SetTextBkColor(RGB(0xec, 0xf1, 0xfd));
m_list_friend.SetHoverTime(1000000);
//添加列
if(-1 == m_list_friend.InsertColumn(0, &lvc))
{
MessageBox("程序出错!");
}
//设置图标
m_list_friend.SetImageList(&m_imlist, LVSIL_SMALL);
return 0;
}
int CUserInfoDlg::InitData()
{
CUserArray alluser;
g_pdbReader->ShowAllUser(alluser);
int n = alluser.size();
//初始化图标
CString all_icon_path = ".\\icon\\icon";
CString the_icon_path = "";
for(int i = 0; i < MAXICON; i++)
{
the_icon_path.Format("%s_%d.ico", all_icon_path, i);
m_imlist.Add( HCH_LoadIcon(the_icon_path) );
}
CString buffer;
LVITEM lvitem;
lvitem.mask = LVIF_IMAGE | LVIF_TEXT;
lvitem.iSubItem = 0;
for (int j = 0; j < n; j++)
{
lvitem.iItem = j;
buffer.Format("%d", alluser[j].num);
lvitem.pszText = buffer.GetBuffer(0);
buffer.ReleaseBuffer();
lvitem.iImage = alluser[j].pic_serial;
m_list_all.InsertItem(&lvitem);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询