求:把数据库的表的内容显示到列表控件里,并实现添加修改删除的功能
求:把数据库的表的内容显示到列表控件里,并实现添加修改删除的功能的步骤及代码。help,求大神帮帮忙。。。谢谢!...
求:把数据库的表的内容显示到列表控件里,并实现添加修改删除的功能的步骤及代码。help,求大神帮帮忙。。。谢谢!
展开
2016-06-21
展开全部
列表显示只是一个表象,二者没有设定好的关联。实际的删除操作应该在数据库中进行,也就是执行删除工作后,你得把列表数据刷新一下,重新显示。
具体的函数实现,如果需要我再贴上来。
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 based m_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;
}
具体的函数实现,如果需要我再贴上来。
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 based m_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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询