本人学习使用CListCtrl控件,现在的问题是,当我想通过函数实现不同窗口的数据传递时,数据可以传过来,但是想通过CListCtrl控件显示出来就总是报错,请问如何解决这个问题这是显示界面的初始化BOOL CLoopState::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//初始化操作
m_listctrl.InsertColumn(0,"地址",LVCFMT_LEFT,80);
m_listctrl.InsertColumn(1,"状态",LVCFMT_LEFT,100);
m_listctrl.InsertColumn(2,"类型",LVCFMT_LEFT,120);
m_listctrl.InsertColumn(3,"设备类型",LVCFMT_LEFT,160); m_listctrl.SetReadOnlyColumns(0);//read only
m_listctrl.SetComboColumns(1,TRUE);
m_listctrl.SetComboColumns(2,TRUE);
m_listctrl.SetComboColumns(3,TRUE);
m_listctrl.EnableVScroll();
m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES);// LVS_EX_GRIDLINES 表格线
CString str;
for(int i=0;i<198;i++)
{
if(i<9)
{
str.Format("00%d",i+1);
}
else if(i>=9&&i<99)
{
str.Format("0%d",i+1);
}
else
{
str.Format("%d",i+1);
}
m_listctrl.InsertItem(LVIF_TEXT|LVIF_STATE, i,
str, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED, 0, 0);
m_listctrl.SetItemText(i,1,"未接");
m_listctrl.SetItemText(i,2,"未定义");
m_listctrl.SetItemText(i,3,"未定义");
}
//设置CListCtrl焦点在第一行
m_listctrl.SetItemState(0, LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
接受传递来的数据的函数void CLoopState::FastSet(int b, int e, CString state, CString type, CString etype)
{
// TODO: Add your control notification handler code here
for(int i=b;i<e+1;i++)
{
m_listctrl.SetItemText(i,1,state);
m_listctrl.SetItemText(i,2,type);
m_listctrl.SetItemText(i,3,etype);
}
}弹出窗口的确定按钮void CFast::OnOK()
{
CString strState,strType,strEtype; CLoopState lsdlg;
m_cmbState.GetWindowText(strState);
m_cmbType.GetWindowText(strType);
m_cmbEtype.GetWindowText(strEtype);
lsdlg.FastSet(m_value_begin,m_value_end,strState,strType,strEtype);
CDialog::OnOK();
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//初始化操作
m_listctrl.InsertColumn(0,"地址",LVCFMT_LEFT,80);
m_listctrl.InsertColumn(1,"状态",LVCFMT_LEFT,100);
m_listctrl.InsertColumn(2,"类型",LVCFMT_LEFT,120);
m_listctrl.InsertColumn(3,"设备类型",LVCFMT_LEFT,160); m_listctrl.SetReadOnlyColumns(0);//read only
m_listctrl.SetComboColumns(1,TRUE);
m_listctrl.SetComboColumns(2,TRUE);
m_listctrl.SetComboColumns(3,TRUE);
m_listctrl.EnableVScroll();
m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES);// LVS_EX_GRIDLINES 表格线
CString str;
for(int i=0;i<198;i++)
{
if(i<9)
{
str.Format("00%d",i+1);
}
else if(i>=9&&i<99)
{
str.Format("0%d",i+1);
}
else
{
str.Format("%d",i+1);
}
m_listctrl.InsertItem(LVIF_TEXT|LVIF_STATE, i,
str, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED, 0, 0);
m_listctrl.SetItemText(i,1,"未接");
m_listctrl.SetItemText(i,2,"未定义");
m_listctrl.SetItemText(i,3,"未定义");
}
//设置CListCtrl焦点在第一行
m_listctrl.SetItemState(0, LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
接受传递来的数据的函数void CLoopState::FastSet(int b, int e, CString state, CString type, CString etype)
{
// TODO: Add your control notification handler code here
for(int i=b;i<e+1;i++)
{
m_listctrl.SetItemText(i,1,state);
m_listctrl.SetItemText(i,2,type);
m_listctrl.SetItemText(i,3,etype);
}
}弹出窗口的确定按钮void CFast::OnOK()
{
CString strState,strType,strEtype; CLoopState lsdlg;
m_cmbState.GetWindowText(strState);
m_cmbType.GetWindowText(strType);
m_cmbEtype.GetWindowText(strEtype);
lsdlg.FastSet(m_value_begin,m_value_end,strState,strType,strEtype);
CDialog::OnOK();
void CLoopState::FastSet(int b, int e, CString state, CString type, CString etype)
{
// TODO: Add your control notification handler code here
for(int i=b;i<e+1 && i<m_listctrl.GetItemCount();i++)
{
m_listctrl.SetItemText(i,1,state);
m_listctrl.SetItemText(i,2,type);
m_listctrl.SetItemText(i,3,etype);
}
}
void CLoopState::FastSet(int b, int e, CString state, CString type, CString etype)
{
// TODO: Add your control notification handler code here
for(int i=b;i<e+1;i++)
{
m_listctrl.SetItemText(i,1,state);
m_listctrl.SetItemText(i,2,type);
m_listctrl.SetItemText(i,3,etype);
}
}CListCtrl控件的SetItemText函数是初始化的时候用的,不过我找不到如何修改数据方法,所以上来求教大家!