zoukankan      html  css  js  c++  java
  • mfc控件使用--- combobox 控件

    //消除现有所有内容
    ((CComboBox*)GetDlgItem(IDC_COMBOBOX))->ResetContent();
    //初始化
    for(int i=0; i<=100; i++)
    {
       strTemp.Format("%d", i);
       ((CComboBox*)GetDlgItem(IDC_COMBOBOX))->AddString(strTemp);
    }
    //取得目前已经有的行数
    int iCount = ((CComboBox*)GetDlgItem(IDC_COMBOBOX))->GetCount();

     

    其他一些常用的函数:

      int iPos=((CComboBox*)GetDlgItem(IDC_COMBO_CF))->GetCurSel();//当前选中的行。

      ((CComboBox*)GetDlgItem(IDC_COMBO_CF))->SetCurSel(n)//设置第n行内容为显示的内容。

      ((CComboBox*)GetDlgItem(IDC_COMBO_CF))->GetWindowText(strTemp);//取当前内容

      ((CComboBox*)GetDlgItem(IDC_COMBO_CF))->GetLBText(n,strTemp);//取其他行内容

      DeleteString( UINT nIndex )//删除指定行

      InsertString( int nIndex, LPCTSTR lpszItem )//将行插入到指定位置

      FindString( int nStartAfter, LPCTSTR lpszItem )//可以在当前所有行中查找指定的字符传的位置,nStartAfter指明从那一行开始进行查找。 
      int SelectString( int nStartAfter, LPCTSTR lpszItem )//可以选中包含指定字符串的行

      为了方便对combobox的操作,通常通过向导类添加一个关联控件的变量m_combo。 也可以手动添加,先在头文件中添加语句 CComboBox m_combo; 然后在DoDataExchange()函数中添加语句 DDX_Control(pDX, IDC_COMBO, m_combo);

      CBN_DROPDOWN事件,点击弹出下拉框事件,在这儿可以更新数据,如下:

    void CMyControl2::OnDropdownCombo() 
    {
        // TODO: Add your control notification handler code here
        //可以在这里更新组合框数据
        m_combo.ResetContent();
        int i;
        CString str;
        static int iflg = 0;
        if (0==(iflg++%2))
        {
            for (i=0; i<101; i+=2)
            {
                str.Format("%d", i);
                m_combo.AddString(str);
            }
        }
        else
        {
            for (i=1; i<101; i+=2)
            {
                str.Format("%d", i);
                m_combo.AddString(str);
            }
        }
        m_combo.SetCurSel(0);
    }
  • 相关阅读:
    2018年3月至4月小结
    前端面试中,经常看到垂直居中与水平居中,实际排版用的多吗?
    Hbuilder配置识别逍遥安卓模拟器
    php静态变量与方法与phar的使用
    切面反射获取方法
    Spring:源码解读Spring IOC原理
    怎样批量提取JPG照片的文件名
    如何1秒批量提取电脑文件夹中的所有文件、文件夹名字到txt/excel
    用powermock 方法中new对象
    springboot单元测试自动回滚:@Transactional
  • 原文地址:https://www.cnblogs.com/hhj-321/p/3371171.html
Copyright © 2011-2022 走看看