zoukankan      html  css  js  c++  java
  • VC CListBox用法总结

    CListBox添加项,得到选中的单项或多项的值。

    OnInitDialog();函数里初始化

    // TODO: 在此添加额外的初始化代码
    CListBox *pCtrl = (CListBox *)GetDlgItem(IDC_LIST1);
    pCtrl
    ->AddString(_T("A"));
    pCtrl
    ->AddString(_T("B"));

     对CListBox的操作

    大气象
    void CUseControlDlg::OnBnClickedButtonOk()
    {
        
    // TODO: 在此添加控件通知处理程序代码
        CListBox *m_lstInfo = (CListBox *)GetDlgItem(IDC_LIST1);
        
        
    //那么你可以用一个循环取出里面的值:
        /*
        CString str; //临时变量用来接收项的字符串
        CString strAll=_T(""); //所有项
        int nCount = m_lstInfo->GetCount();//得到项目总数
        for(int i = 0; i< nCount; ++i)
        {
            m_lstInfo->GetText(i,str);
            strAll = strAll + str + _T("\r\n");
        }
        AfxMessageBox(strAll);
        
    */

        
    //取出单选选中的值
        /*
        int index;
        CString selectStr;
        index = m_lstInfo->GetCurSel();
        m_lstInfo->GetText(index,selectStr);
        AfxMessageBox(selectStr);
        
    */

        
    //多选,设置selection为Multiple
        int nCount = m_lstInfo->GetSelCount();
        CString cCount;
        CArray
    <int,int> aryListBoxSel;

        aryListBoxSel.SetSize(nCount);
        m_lstInfo
    ->GetSelItems(nCount, aryListBoxSel.GetData()); 
        
    //得到总数
        cCount.Format(_T("%d"),nCount);
        AfxMessageBox(cCount);
        
    //得到选中的多项
        for (int i=0;i<nCount;i++)
        {
            CString selStr;
            m_lstInfo
    ->GetText(aryListBoxSel[i],selStr);
            AfxMessageBox(selStr);
        }
    天祺围棋:www.tianqiweiqi.com呵呵

    凡事以大气象去面对,优秀是一种习惯。

  • 相关阅读:
    【R】爬虫案例
    [R] 保存pheatmap图片对象到文件
    [R] 添加误差棒的分组折线图:geom_path: Each group consists of only one observation. Do you need to adjust the...
    [R] read.table/read.delim读入数据行数变少?
    [R] cbind和filter函数的坑
    [R]在dplyr函数的基础上编写函数(3)tidyeval
    [R]在dplyr基础上编写函数(2)substitute和quote
    30个Java知识点
    Java的30个知识点
    40个知识点
  • 原文地址:https://www.cnblogs.com/greatverve/p/clistbox.html
Copyright © 2011-2022 走看看