mfc中怎样往列表框中添加多列数据
BOOLCListdlgDlg::OnInitDialog(){CDialog::OnInitDialog();CStringstr[4]={"姓名","学号","成绩"...
BOOL CListdlgDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString str[4]={"姓名","学号","成绩","学分"};
for(int i=0;i<4;i++)
{
m_list.InsertColumn(i,str[i],LVCFMT_LEFT,80);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CListdlgDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char ch1[255];
char ch2[255];
char ch3[255];
char ch4[255];
static int i=0;
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,255);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,255);
GetDlgItem(IDC_EDIT3)->GetWindowText(ch3,255);
GetDlgItem(IDC_EDIT4)->GetWindowText(ch4,255);
m_list.SetItemText(i,0,ch1);
m_list.SetItemText(i,1,ch2);
m_list.SetItemText(i,2,ch3);
m_list.SetItemText(i,3,ch4);
i++;
}
这样做有错吗?为什么无法添加数据 展开
{
CDialog::OnInitDialog();
CString str[4]={"姓名","学号","成绩","学分"};
for(int i=0;i<4;i++)
{
m_list.InsertColumn(i,str[i],LVCFMT_LEFT,80);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CListdlgDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char ch1[255];
char ch2[255];
char ch3[255];
char ch4[255];
static int i=0;
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,255);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,255);
GetDlgItem(IDC_EDIT3)->GetWindowText(ch3,255);
GetDlgItem(IDC_EDIT4)->GetWindowText(ch4,255);
m_list.SetItemText(i,0,ch1);
m_list.SetItemText(i,1,ch2);
m_list.SetItemText(i,2,ch3);
m_list.SetItemText(i,3,ch4);
i++;
}
这样做有错吗?为什么无法添加数据 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询