📄 subject_21076.htm
字号:
<p>
序号:21076 发表者:qiaofeng 发表日期:2002-11-13 15:22:17
<br>主题:有关List Control的疑问
<br>内容:List Control这个控件在对话框里可以显示数据库的记录吗?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:啊志 回复日期:2002-11-13 16:11:31
<br>内容:可以呀,你先取数据集,然后逐条将数据库记录添加到LIST里
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:qiaofeng 回复日期:2002-11-13 16:20:31
<br>内容:啊志,你能不能说详细点,我弄了好久都没弄出来
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:啊志 回复日期:2002-11-13 17:08:16
<br>内容:你的数据库用什么访问的?<BR><BR>VC查询数据库,得到数据,在遍历纪录,逐条将数据库记录添加到LIST里
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:cool 回复日期:2002-11-13 17:13:06
<br>内容:可以,我就是这样做的,不过你要先打开数据库,读取到你所要的数据才能显示啊。<BR><BR>你是不是想象VB和VFP那样设置数据源啊,很遗憾,VC的ListCtrl控件好像没有这样的方法属性,你必须用CDatabase、CRecordSet之类的东西先获取数据,然后再用你在VC栏目的方法去实现.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:qiaofeng 回复日期:2002-11-13 19:21:19
<br>内容:我的数据源是ODBC,数据库是SQL Server呀,我先在ResouceView里添加了一个对话框,用ClassWizard里添加了一个新的基于CDialog的类CFindDialog,这个对话框用于输入我要查询的内容。然后又添加了一个对话框,这个对话框里面放了List Control这个控件,用ClassWizard里添加了一个新的基于CDialog的类CInsertDialog,这个对话框用于显示查询到的记录。我在CInsertDialog里面添加了一个OnInitDialog()的函数,用于初始化List Control。代码如下:<BR>BOOL CInsertdialog::OnInitDialog() <BR>{<BR> CDialog::OnInitDialog();<BR> m_UserList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);<BR> m_UserList.InsertColumn(0,_T("学号"));<BR> m_UserList.InsertColumn(1,_T("年令"));<BR> m_UserList.InsertColumn(2,_T("姓名"));<BR> int j;<BR> for(j=0;j<3;j++)<BR> {<BR> m_UserList.SetColumnWidth(j ,90);<BR> }<BR> return TRUE; <BR> }<BR>然后我有个查询函数OnFind()<BR>代码如下:<BR>void CMyView::OnFind() <BR>{<BR> BOOL k=FALSE;<BR> int i=0;<BR> CFinddialog dlg;<BR> CInsertdialog dlgxianshi;<BR> if(dlg.DoModal()==IDOK)<BR> {<BR> if (m_pSet->IsOpen())<BR> m_pSet->Close();//以便下面用函数m_pSet->Open<BR> CString fxm=dlg.m_fxm;<BR> CString strstmt;<BR> strstmt.Format("SELECT * FROM [dbo].[bmk] where [bumen]='%s'",fxm);<BR> m_pSet->Open(AFX_DB_USE_DEFAULT_TYPE, strstmt);<BR> if(!m_pSet->IsEOF())<BR> {<BR> k=TRUE;<BR> m_pSet->MoveFirst();<BR> do<BR> {<BR> AfxMessageBox(m_pSet->m_name);//用于监视m_pSet->m_name<BR> dlgxianshi.m_UserList.InsertItem(i,m_pSet->m_name);<BR> dlgxianshi.m_UserList.SetItemText(i,1,m_pSet->m_mima);<BR> dlgxianshi.m_UserList.SetItemText(i,2,m_pSet->m_bumen);<BR> i++;<BR> m_pSet->MoveNext();<BR> }while(!m_pSet->IsEOF());<BR> if(dlgxianshi.DoModal()==IDOK)<BR> {<BR> }//结束if(dlgxianshi.DoModal()==IDOK)<BR> }//结束if(!m_pSet->IsEOF())<BR> if(k==FALSE)<BR> AfxMessageBox("没有符和条件的记录");<BR> }//第一个if <BR>}<BR>我发现每次记录集里有记录,而且m_pSet->name,m_pSet->mima,m_pSet->bumen都是char型的,编译通过后运行到AfxMessageBox(m_pSet->m_name);显示查到的一个名字后,出现<BR>一个有三个选项按纽重试、忽略、取消的警告框,无论按哪个都自动退出程序的错误。大家帮我看看怎么回事?<BR>2002-11-14 8:41:46
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -