BOOL CListview::OnInitDialog()
{
CDialog::OnInitDialog();
CFont m_ListFont;
m_ListFont.CreatePointFont(120,"宋体");
DWORD dwExStyle = m_listview.GetExStyle();
dwExStyle&=~LVS_EX_CHECKBOXES;
m_listview.SetFont(&m_ListFont);
m_listview.SetExtendedStyle(dwExStyle|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
TEXTMETRIC tm;
CDC*pDC=GetDC();
pDC->GetTextMetrics(&tm);
m_listview.InsertColumn(0,"ID",LVCFMT_CENTER,90,0);
m_listview.InsertColumn(1,"姓名",LVCFMT_CENTER,120,0);
m_listview.InsertColumn(2,"性别",LVCFMT_CENTER,90,0);
m_listview.InsertColumn(3,"年龄",LVCFMT_CENTER,90,0);
m_listview.InsertColumn(4,"分数",LVCFMT_CENTER,120,0);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
然后点击主界面的查询按钮时,显示该对话框,当点击OK按钮时显示在Listcontrol,主程序代码如下:
void CTEST1View::OnView()
{
CListview rv;
rv.DoModal();
COleVariant var; // 字段类型
var.ChangeType(VT_BSTR,NULL);
CListCtrl m_view;
m_view.DeleteAllItems();//清空表
CDaoDatabase db;
CDaoRecordset RecSet(&db);
db.Open("data.mdb");
RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM person",NULL);
CString str[4];
CString str1;
int i=0;
int j=0;
while(!RecSet.IsEOF())
{
RecSet.GetFieldValue("ID",var);
str[0]=var.intVal;
RecSet.GetFieldValue("姓名",var);
str[1]=(LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("性别",var);
str[2]=(LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("年龄",var);
str[3]=var.intVal;
RecSet.GetFieldValue("分数",var);
str[4].Format("%10.6f",var.dblVal);
str1.Format("%d",i);
m_view.InsertItem(i,str1);//这条很重要,是创建了一个新的行
for(j=0;j<=4;j++)
m_view.SetItemText(i,j,str[j]);
i=i+1;
RecSet.MoveNext();
}
RecSet.Close();
db.Close();
// TODO: Add your command handler code here
}
但是,运行出了问题。。。。十万火急,在线等,请大侠们赐教
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录