Report风格的ListCtrl的扩展,原文链接地址:http://www.codeproject.com/Articles/5560/Another-Report-List-Control

1.列排序

BOOL IsSortable() const; // Is sort allowed?
BOOL SetSortable(BOOL bSet); // Allow/disallow sorting
BOOL IsSortAscending() const;
int GetSortedColumn() const;
// Sort a specified column.
void SortItems(int nColumn, BOOL bAscending);

A message WM_ITEM_SORTED is sent to the parent window after a sorting is completed, the column index is passed as wParam and sorting method is passed as lParam (0=descending, 1=ascending).

2.列中排序

单列中,按照每一部分排列,如separator一部分进行排列。

1)不用字符串进行排列:

m_wndList.SetSortSeparator(NULL); // Disable sort-separator
// Sort the first column in ascending order
m_wndList.SortItems(0, TRUE);

2)按照separator字符串进行排列:

// m_wndList.SetSortSeparator(NULL); // Disable sort-separator
// m_wndList.SortItems(0, TRUE); // Sort the first column in ascending order // Use string "Separator" as the sort-separator
m_wndList.SetSortSeparator(_T("Separator"));
// Sort the first column in ascending order
m_wndList.SortItems(0, TRUE);
  • 2)其他相关函数:

  • void SetSortSeparator(LPCTSTR lpSortSeparator);
    LPCTSTR GetSortSeparator() const;

    3.子项可编辑

  • BOOL IsEditable() const; // Is Item text editable?
    void SetEditable(BOOL bSet = TRUE); // Allow item text editting // Display the editbox, previous edit are committed
    BOOL StartEdit(int nItem, int nSubItem); BOOL EndEdit(BOOL bCommit = TRUE); // Commit/cancel text edit, hide the editbox
    CEdit* GetEditControl();

    4.自定义框选

    void SetCheckboxeStyle(int nStyle = RC_CHKBOX_NORMAL); // Set checkbox styles.
    int GetCheckboxStyle() const;
    ----------------------------nStyle------------------------------------------------------------- 
    • RC_CHKBOX_NONE -- No checkbox displayed
    • RC_CHKBOX_NORMAL -- Normal style, multiple check marks allowed
    • RC_CHKBOX_SINGLE -- Single check only. Checkboxes are mutually exclusive, just like using radio buttons.
    • RC_CHKBOX_DISABLED -- Disabled, cannot be checked/unchecked by user input.
    // Example:
    
    // Make the checkbox read-only
    m_wndList.SetCheckboxeStyle(RC_CHKBOX_DISABLED);

    5.列图标、子项颜色、子项图标

    // Column header images
    BOOL SetHeaderImage(int nColumn, int nImageIndex, BOOL bLeftSide = TRUE);
    int GetHeaderImage(int nColumn) const;
    CImageList* SetHeaderImageList(UINT nBitmapID, COLORREF crMask = RGB(255, 0, 255));
    CImageList* SetHeaderImageList(CImageList* pImageList);

    // Sub-item images
    BOOL SetItemImage(int nItem, int nSubItem, int nImageIndex);
    int GetItemImage(int nItem, int nSubItem) const;
    CImageList* SetImageList(UINT nBitmapID, COLORREF crMask = RGB(255, 0, 255));
    CImageList* SetImageList(CImageList* pImageList);
    CImageList* GetImageList() const;

    // Sub-item Text & Background Color
    void SetItemTextColor(int nItem = -1, int nSubItem = -1,
    COLORREF color = COLOR_INVALID, BOOL bRedraw = TRUE);
    COLORREF GetItemTextColor(int nItem, int nSubItem) const;
    void SetItemBkColor(int nItem = -1, int nSubItem = -1,
    COLORREF color = COLOR_INVALID, BOOL bRedraw = TRUE);
    COLORREF GetItemBkColor(int nItem, int nSubItem) const;

    // Example: Set image and color for grid - 1st row 3rd column
    
    m_wndList.SetImageList(IDB_BITMAP1); // Using bitmap resource "IDB_BITMAP1"
    m_wndList.SetItemImage(0, 2, 0); // Set the 1st row 3rd column with image index 0 // Set grid colors
    m_wndList.SetItemTextColor(0, 2, RGB(255, 0, 0), TRUE); // Grid text color: red
    m_wndList.SetItemBkColor(0, 2, RGB(0, 255, 0), TRUE); // Grid bkground color: green

    6.方便操作

    1)操作属性

    RC_ITEM_ALL - All items regardless of states
    RC_ITEM_SELECTED - Selected items
    RC_ITEM_UNSELECTED - Unselected items
    RC_ITEM_CHECKED - Checked items
    RC_ITEM_UNCHECKED - Unchecked items
    RC_ITEM_FOCUSED - Focused item
    RC_ITEM_UNFOCUSED - Unfocused items

    2)相关函数

    int GetFirstItem(DWORD dwStates = RC_ITEM_ALL, int nStartAfter = -1) const;
    int GetLastItem(DWORD dwStates = RC_ITEM_ALL, int nStartBefore = -1) const;
    int GetItemCount(DWORD dwStates = RC_ITEM_ALL) const;
    DWORD GetItemStates(int nItem) const;
    BOOL ExamItemStates(int nItem, DWORD dwStates) const;
    BOOL SetItemStates(int nItem, DWORD dwNewStates);
    int SetAllItemStates(DWORD dwOldStates, DWORD dwNewStates);
    void InvertItems(int nType); // RC_INVERT_SELECTION or RC_INVERT_CHECKMARK

    3)example

    // Example:
    
    // Select all items which were unselected and unchecked
    m_wndList.SetAllItemStates(RC_ITEM_UNSELECTED | RC_ITEM_UNCHECKED, RC_ITEM_SELECTED); // How many items are not checked?
    int n = m_wndList.GetItemCount(RC_ITEM_UNCHECKED); //Unselect and check all items regardless of their previous states
    m_wndList.SetAllItemStates(RC_ITEM_ALL, RC_ITEM_UNSELECTED | RC_ITEM_CHECKED); // Delete all items which were selected and checked
    m_wndList.DeleteAllItems(RC_ITEM_SELECTED | RC_ITEM_CHECKED);

    7.方便定位

    int MoveUp(int nItem, int nCount = 1); // Move an item upwards by "nCount" positions.
    
    // Move an item downwards by "nCount" positions.
    int MoveDown(int nItem, int nCount = 1); int MoveToTop(int nItem); // Move an item up to the top.
    int MoveToBottom(int nItem); // Move an item down to the bottom.
    int MoveTo(int nItem, int nNewPosition); // Move an item to a particular position
    BOOL SwapItems(int nItem1, int nItem2); // Swap two items including all attributes.

    8.内容项操作

    BOOL SetItemText(int nItem, int nSubItem, INT val);
    BOOL SetItemText(int nItem, int nSubItem, UINT val);
    BOOL SetItemText(int nItem, int nSubItem, LONG val);
    BOOL SetItemText(int nItem, int nSubItem, ULONG val);
    BOOL SetItemText(int nItem, int nSubItem, TCHAR val);
    BOOL SetItemText(int nItem, int nSubItem, DOUBLE val, int nPrecision = -1);
    BOOL SetItemText(int nItem, int nSubItem,
    const COleDateTime& dateTime,
    DWORD dwFlags = 0);

    9.自适应

    void CMyView::OnSize(UINT nType, int cx, int cy)
    {
    CFormView::OnSize(nType, cx, cy); // TODO: Add your message handler code here
    m_wndList.ResizeToFitParent(); // Add this line!
    }

    10.例子

    m_wndList.SetColumnHeader(_T("Student ID, 100; Enroll Date, 150; Score, 80, 2"));
    
        for (int i = 0; i < 10; i++)
    {
    const int IDX = m_wndList.InsertItem(0, _T(""));
    m_wndList.SetItemText(IDX, 0, rand() % 3000);
    m_wndList.SetItemText(IDX, 1, GenRandDate());
    m_wndList.SetItemText(IDX, 2, (rand() % 51) + 50); for (int j = 0; j < 2; j++)
    m_wndList.SetItemImage(IDX, j, rand() % 5); // subitem images } m_wndList.SetImageList(IDB_BITMAP1);
    m_wndList.SetHeaderImageList(IDB_BITMAP2);
    m_wndList.SetHeaderImage(0, 0);
    m_wndList.SetHeaderImage(1, 2, FALSE);
    m_wndList.SetHeaderImage(2, 1);
    m_wndList.SetGridLines(TRUE); // SHow grid lines
    m_wndList.SetCheckboxeStyle(RC_CHKBOX_NORMAL); // Enable checkboxes
    m_wndList.SetEditable(TRUE); // Allow sub-text edit
    m_wndList.SortItems(0, TRUE); // sort the 1st column, ascending
    m_bSortable = m_wndList.IsSortable();
    UpdateData(FALSE);
    GetDlgItem(IDC_ALLOWSORT)->EnableWindow(m_wndList.HasColumnHeader()); // now play some colorful stuff // Set the 3rd column background color to yellow, text color to blue
    m_wndList.SetItemTextColor(-1, 2, RGB(0, 0, 0));
    m_wndList.SetItemBkColor(-1, 2, RGB(255, 255, 0)); for (int n = 0; n < m_wndList.GetItemCount(); n++)
    {
    const int SCORE = _ttoi(m_wndList.GetItemText(n, 2)); // student score if (SCORE < 60)
    {
    m_wndList.SetItemBkColor(n, -1, ::GetSysColor(COLOR_INFOBK));
    m_wndList.SetItemTextColor(n, -1, RGB(255, 0, 0)); m_wndList.SetItemBkColor(n, 2, RGB(255, 0, 0));
    m_wndList.SetItemTextColor(n, 2, RGB(255, 255, 255));
    }
    else if (SCORE > 90)
    {
    m_wndList.SetItemBkColor(n, -1, RGB(160, 255, 192));
    m_wndList.SetItemTextColor(n, -1, RGB(0, 0, 255)); m_wndList.SetItemTextColor(n, 2, RGB(255, 255, 255));
    m_wndList.SetItemBkColor(n, 2, RGB(0, 160, 0));
    }
    }

  • 代码链接地址:http://download.csdn.net/detail/wuyuan2011woaini/9592993

    Report List Controls的更多相关文章

    1. Percona Toolkit 使用

      安装 percona-toolkit perl Makefile.PL make make test make install 默认安装到 /usr/local/bin 目录下 可能需要 DBI-1. ...

    2. WPF Combox实现下拉多选,可选中多个值

      自定义多选MultiCombox,可以实现下拉列表多选 using System; using System.Collections.Generic; using System.Collections ...

    3. Session for SSRS Report of Microsoft Dynamics AX

      Session for SSRS Report of Microsoft Dynamics AX 版权声明:本文为博主原创文章,未经博主允许不得转载. Contract •A data contrac ...

    4. Report processing of Microsoft Dynamic AX

      Report processing of Microsoft Dynamic AX 版权声明:本文为博主原创文章,未经博主允许不得转载. The implementation of a general ...

    5. SQL Server 2008 R2 升级到 Service Pack 3后Report Builder启动不了

      一同事将测试服务器从SQL Server 2008 R2 SP2升级到了SQL Server 2008 R2 SP3后发现Report Service的报表编辑时启动不了Report Builder, ...

    6. Crystal Report在.net中的两种显示方式

      Crystal Report在.net中的两种显示方式 编写人:CC阿爸 2014-7-29 近来在完成深圳一公司的项目,对方对各方面要求相当严格,一不满意就拒绝签收,为了对修正水晶报表显示及导出的一 ...

    7. [转] Asp.net Report Viewer 简单实例

      原文链接:http://www.aspsnippets.com/Green/Articles/ASPNet-Report-Viewer-control-Tutorial-with-example.as ...

    8. USB HID Report Descriptor 报告描述符详解

      Report descriptors are composed of pieces of information. Each piece of information is called an Ite ...

    9. DevExpress ASP.NET Core Controls 2019发展蓝图(No.4)

      本文主要为大家介绍DevExpress ASP.NET Core Controls 2019年的官方发展蓝图,更多精彩内容欢迎持续收藏关注哦~ [DevExpress ASP.NET Controls ...

    随机推荐

    1. JS魔法堂:精确判断IE的文档模式by特征嗅探

      一.前言 苦逼的前端攻城狮都深受浏览器兼容之苦,再完成每一项功能前都要左顾右盼,生怕浏览器不支持某个API,生怕原生API内含臭虫因此判断浏览器类型和版本号成了不可绕过的一道关卡,而特征嗅探是继浏览器 ...

    2. (一)JAVA项目(非web项目)部署到windows服务器运行

      [转]http://blog.csdn.net/tracy19880727/article/details/11205063 一般服务器运行的几乎都是web项目,今天遇到一个问题,把写好的Java项目 ...

    3. 使用“原生”HTML DOM获取input的输入值并显示

      理论基础 HTML <input> value属性.value规定<input>元素的值.value对于不同input类型,用法也不同. 1.对于"button&qu ...

    4. Google判断广告点击作弊的几种方式和数据

       Google判断广告点击作弊的几种方式和数据. 作弊广告点击的CTR数据太高网上有研究说如果CTR值大于了10%的站被干掉的可能性很高,他们会被单独拿出来分析.一般来说低于6-7%的CTR是安全红线 ...

    5. SQL索引学习-索引结构

      前一阵无意中和同事讨论过一个SQL相关的题(通过一个小问题来学习SQL关联查询),很惭愧一个非常简单的问题由于种种原因居然没有回答正确,数据库知识方面我算不上技术好,谈起SQL知识的学习我得益于200 ...

    6. Python基础:序列(列表、元组)

      一.概述 列表(list)是由一个个 Python对象 组成的序列.其中,Python对象 可以是任何类型的对象,包括 Python标准类型(数值.字符串.列表.元组和字典)以及 用户自定义类型(类) ...

    7. SqlServer根据时段统计数据

      create table ST_PPTN_R_Real ( TID int primary key identity(1,1), STCD varchar(100) not null, TM date ...

    8. 【学习整理】NOIP涉及的数论 [updating]

      扩展欧几里得 求二元一次不定式方程 的一组解. int exgcd(int a,int b,int &x,int &y) { int t; ;y=;return a;} t=exgcd ...

    9. [Xamarin.iOS] Visual Studio中Xamarin.iOS项目,无法加入PCL项目参考、NuGet组件参考

      [Xamarin.iOS] Visual Studio中Xamarin.iOS项目,无法加入PCL项目参考.NuGet组件参考 解决方案 目前Visual Studio中最新版本的Xamarin.iO ...

    10. PFold.js 折叠纸片

      PFold.js是一款折叠纸片插件,支持定义折叠纸牌数量.折叠动画效果.折叠方向,而且还支持折叠结束后回调方法. 在线实例 效果一 效果二 效果三 使用方法 <div id="uc-c ...