我们现在一般都用的ado类库自己写相关的代码,在对话框上增加一个控件clistctrl然后用它的成员函数把查询结果一条一条插入进去clistctrl::insertitem();clistctrl::setitemtext();查询就用ado接口来完成,灵活性要大些,但是肯定比activex控件要繁琐些。
列表显示只是一个表象,二者没有设定好的关联。实际的删除 *** 作应该在数据库中进行,也就是执行删除工作后,你得把列表数据刷新一下,重新显示。具体的函数实现,如果需要我再贴上来。
void CMCTTView::ListItem()//刷新列表
{
int i = 0
if(!m_pSet->IsOpen())
AfxMessageBox("数据源未打开")
m_Item.SetExtendedStyle(m_Item.GetExtendedStyle()|LVS_EX_FULLROWSELECT)
m_Item.DeleteAllItems()
m_Item.SetRedraw(FALSE)
if (!m_pSet->GetRecordCount() == 0)
{
m_pSet->MoveFirst()
}
while(!m_pSet->IsEOF())
{
m_Item.InsertItem(i,"")
m_Item.SetItemText(i,0,m_pSet->m_column1)
m_Item.SetItemText(i,1,m_pSet->m_column2)
m_Item.SetItemText(i,2,m_pSet->m_column3)
m_Item.SetItemText(i,3,m_pSet->m_column4)
i+=1
m_pSet->MoveNext()
}
m_Item.SetRedraw(TRUE)
}
void CMCTTView::OnItemDel() //在view类中删除条目
{
// TODO: Add your control notification handler code here
int listIndex //当前选中项的索引
//首先得到点击的位置
POSITION pos=m_Item.GetFirstSelectedItemPosition()//0 basedm_item是指代列表控件
if(pos==NULL)
return
//得索引,通过POSITION转化
listIndex=m_Item.GetNextSelectedItem(pos)+1//1 based,so 1 added
m_pSet->SetAbsolutePosition(listIndex)
if ( MessageBox( _T( "你确定要删除当前单词信息吗?" ),
_T( "删除确认?" ), MB_OKCANCEL | MB_ICONQUESTION ) == IDOK )
{
m_pSet->Delete()
MessageBox( _T( "该单词信息已经被成功删除!" ),
_T( "删除成功!" ), MB_OK | MB_ICONASTERISK )
OnNext()
}
m_pSet->Requery()
//if(!m_pSet->GetRecordCount() == 0)
ListItem()
}
void CMCTTView::OnNext()
{
m_pSet->MoveNext()
if ( m_pSet->IsEOF() )
m_pSet->MoveFirst()
}
int CMCTTDoc::AddToAcc()//在doc类中添加数据
{
m_mCTTSet.AddNew()
CString str1,str2,str3,str4
str1.Format("%s",m_Index)
str2.Format("%f",m_UseHs)
str3.Format("%f",m_UseHj)
switch (m_HJStyle)
{
case 0:
str4 = CString("类型1")
break
case 1:
str4 = CString("类型2")
break
case 2:
str4 = CString("类型3")
break
}
m_mCTTSet.m_column1 = str1 //Index
m_mCTTSet.m_column2 = str2//the use of hansi
m_mCTTSet.m_column3 = str3//the use of hanji
m_mCTTSet.m_column4 = str4//the style of hanjie
m_mCTTSet.Update()
m_mCTTSet.Requery()
MessageBeep(MB_OK)
CMainFrame* pframe = (CMainFrame*)AfxGetMainWnd()
CMCTTView* pInterfaceView = (CMCTTView*)pframe->GetActiveView()
pInterfaceView->ListItem()
return 0
}
1. 在新对话框类中, 定义变量 m_info 保存你需要的信息2. 创建对象的时候,先给 m_info 赋值
3. 最后d出对话框: DoModal()
或者新对话框类添加一个带参数的构造函数,把参数值保存下来即可
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)