CGridListCtrlEx

来源:互联网 发布:英语六级怎么准备 知乎 编辑:程序博客网 时间:2024/05/16 04:22

原文地址

http://www.codeproject.com/Articles/29064/CGridListCtrlEx-Grid-Control-Based-on-CListCtrl

 

 

Introduction 介绍

 

Microsoft's CListCtrl has support fordisplaying data in a grid using the report style, but we have to make severalchanges to implement features like:

微软的CListCtrl对使用本报告的风格在网格中显示的数据支持,但我们一定要实现类似功能的几个变化:

 

Sorting                                 排序

Cell navigation and keyboard search                 单元格导航和键盘搜索

Tooltips                       提示

Hiding and showing columns   隐藏和显示列

Cell editing                          单元格编辑

HyperLinks                          超链接

Custom row and cell coloring  自排和单元格颜色

Grouping                    分组

Clipboard (copy only)                 剪贴板

Persist column width, position andvisibility              保留列宽,位置和可见性

OLE Drag and Drop (includes reordering ofitems)  OLE拖放

 

 

This article demonstrates how to useCGridListCtrlEx, which implements all the above features while maintaining theWindows XP/Vista look.

本文演示如何使用CGridListCtrlEx ,它实现了上述所有功能,同时保持在Windows XP / Vista的看。

 

The Google Code - CGridListCtrlEx can beused if wanting SubVersion access, and there is also Doxygen Documentation.

不翻译了.无用

 

Background背景

There are lots of advanced grid controlsthat extend the CListCtrl, and one of those is the Enhanced List Control(CGfxListCtrl). This wonderful controlprovides all the above features, but fails to handle Windows XP and Vista.Finding a good replacement for this control is not very easy:

有很多先进的网格控件扩展自CListCtrl.其中之一就是Enhanced List Control(CGfxListCtrl)..

他是非常漂亮的完成了上述功能,但是无法处理winxpvista.找到一个代替的空间很不容易:

·        MFC Grid Control - Doesn't inherit from CListCtrl so it is not restricted byit, but it will not benefit from any improvements that Microsoft adds to the CListCtrl.

·        • MFC网格控件 - 不从CListCtrl的继承所以它不限制它,但它不会从任何改进中获益,微软增加了的CListCtrl

 

·        Ultimate Grid - Like MFC Grid Control, itdoesn't inherit from CListCtrl. Originally one had to buyit, but now it is free to use.

·        •终极格 - 像MFC网格控制,它不会从CListCtrl的继承。本来人们不得不买,但现在它是免费使用。

·         

·        CQuickList - Very close to being aperfect replacement, but hard to add new ways to display data, and it requires LVS_OWNERDATA that makes sorting a littleharder.

·        • CQuickList - 非常接近于一个完美的替代品,但很难增加新的方式来显示数据,它需要LVS_OWNERDATA使排序有点困难。

·         

·        XListCtrl - Also a very complete CListCtrl, but hard to add new ways to display data, and it fails tosupport LVS_OWNERDATA. One now has to buy alicense, to get the latest version.

·         

·        XListCtrl - 也是一个非常完整的CListCtrl ,但很难增加新的方式来显示数据,并不能支持LVS_OWNERDATA。一个现在已经买了牌照,以获取最新版本。

·        Another Report List Control - Simple and easy to use,but lacks other means to edit data besides usingCEdit, and also misses subitemnavigation.

·        •其他报表列表控制 - 简单易用,但缺乏其他手段除了usingCEdit编辑的数据,并且还惦记子项目导航。

·         

·        CListCtrlEx - Implements lots of featureand is well documented. Originally required LVS_OWNERDRAWFIXED, and now evolved into using custom draw. The combination ofboth custom draw and owner draw causes the code to be a little complicated, andit also doesn't support LVS_OWNERDATA.

·        • CListCtrlEx - 实现很多功能,并且有据可查。本来需要LVS_OWNERDRAWFIXED ,现在演变成使用自定义绘制。两者的结合自定义绘制和所有者拉伸使代码是有点复杂,而且它也不支持LVS_OWNERDATA 。

·         

The CGridListCtrlEx inserts an abstract layercalled column traits that handles the cell drawing and editing. In caseMicrosoft extends their CListCtrl again, then hopefully, thecore of CGridListCtrlEx will continue to function.

该CGridListCtrlEx插入一个抽象层,叫做列特质,处理单元绘制和编辑。如果微软扩大自己的CListCtrl一遍,然后希望, CGridListCtrlEx的核心将继续运行。

 

Howto Use the CGridListCtrlEx

The CGridListCtrlEx triesto stay true to the CListCtrl, and doesn't try to replace anything the CListCtrlalready provides. This means we can replace a CListCtrl with CGridListCtrlEx withoutneeding to do anything more.

It is recommended that we don't use the CGridListCtrlEx directly,but create a new class that inherits/derives from CGridListCtrlEx. This will make it easier to migrate any updates there will beto the CGridListCtrlExclass later on.

该CGridListCtrlEx试图忠于的CListCtrl的,并且不尝试更换任何东西CListCtrlalready提供。这意味着我们可以替换CGridListCtrlEx一个CListCtrl ,而无需做任何事情更多。
所以建议大家不要直接使用CGridListCtrlEx ,但创建一个新的类继承自CGridListCtrlEx /导出。这将使它更容易迁移的任何更新将有向CGridListCtrlExclass以后。

EditingCells/Subitems      

编辑单元格/子项

By default, when inserting columns inthe CGridListCtrlEx, they will be configured as read-only, without the ability tobe edited. By using CGridListCtrlEx::InsertColumnTrait(), we can provide aCGridColumnTrait classwhich specifies what type of editor it should use.

 Collapse CopyCode

CGridColumnTrait* pTrait = new CGridColumnTraitEdit;
m_ListCtrl.InsertColumnTrait(nCol, title.c_str(), LVCFMT_LEFT, 100, nCol, pTrait);

Trait----特点的意思

缺省情况下,插入在CGridListCtrlEx列时,它们将被配置为只读的,而不需要编辑的能力。通过使用CGridListCtrlEx:: InsertColumnTrait ( ) ,我们可以提供CGridColumnTrait类指定它应该使用什么类型的编辑器。
When having edited an item, a standard LVN_ENDLABELEDIT message will be sent to the CListCtrl. When theCGridListCtrlEx receives this message, it will automaticallycall the virtual methodCGridListCtrlEx::OnEditComplete(), allowing a derived class to validate theinput and maybe update an underlying data model.

当已编辑的项目,一个标准LVN_ENDLABELEDIT消息将被发送到的CListCtrl 。当theCGridListCtrlEx收到此消息时,它会自动调用虚拟methodCGridListCtrlEx ::OnEditComplete ( ) ,允许派生类验证输入,也许更新底层数据模型。

 

 

 

EditingCells/Subitems with a Combo-box

编辑单元格/子项目  用Combo-box

By using CGridListCtrlEx::InsertColumnTrait(), we can also provide a CGridColumnTrait classwhich works as a CComboBox.

 Collapse CopyCode

CGridColumnTraitCombo* pTrait = new CGridColumnTraitCombo;
pTrait->AddItem(0, "Hello");
pTrait->AddItem(1, "Goodbye");
m_ListCtrl.InsertColumnTrait(nCol, title.c_str(), LVCFMT_LEFT, 100, nCol, pTrait);

We can specify the items of the CComboBox wheninserting the columns (as shown above). If we want to provide the CComboBox itemsdynamically, then we can override the CGridListCtrlEx::OnEditBegin(). Usedynamic_cast<> toeither call the column trait method CGridColumnTraitCombo::LoadList(), or to work on the returned CComboBox-editor directly.  

If wanting to get the itemdata of the CComboBox-item selected, then one can overrideCGridListCtrlEx::OnEditComplete() andcheck the parameter value pLVDI->item.lParam. One is required to save the itemdata elsewhere, as it cannotbe stored inside the local datamodel of CListCtrl.

 

插入的列时(如上图所示),我们可以指定CComboBox快速的项目。如果我们要动态地提供CComboBox快速的项目,那么我们就可以覆盖CGridListCtrlEx :: OnEditBegin( ) 。 Usedynamic_cast < >要么调用列特质方法CGridColumnTraitCombo ::LoadList ( ) ,或直接在返回CComboBox快速编辑器工作。
如果想获得CComboBox快速项选择的的ItemData ,那么可以overrideCGridListCtrlEx ::OnEditComplete ( ),并检查该参数值pLVDI- > item.lParam 。一个需要保存的ItemData别处,因为它不能被存储的CListCtrl的本地数据模型内。

SortingRows 行排序

By default, the GridListCtrlEx willhave sorting enabled for all columns, where it will perform a simpletext-comparison. It is possible through the column traits to implement customsorting by overridingCGridColumnTrait::OnSortRows().

默认情况下,GridListCtrlEx将已启用排序所有列,在那里将进行一个简单的文本比较。因此能够通过该柱的性状来实现通过重写CGridColumnTrait:: OnSortRows定制排序() 。

To configure a column trait to sortusing number comparison:

要配置列特征使用数量比较排序

 Collapse CopyCode

CGridColumnTraitEdit* pTrait = new CGridColumnTraitEdit;
pTrait->SetSortFormatNumber(true); // Numeric column
m_ListCtrl.InsertColumnTrait(nCol, title.c_str(), LVCFMT_LEFT, 100, nCol, pTrait);

The column trait CGridColumnTraitDateTime willautomatically attempt to sort using date comparison.

列特质CGridColumnTraitDateTime会自动尝试使用日期比较排序。

We also have the option to override the CGridListCtrlEx::SortColumn() method.Then, it is just a matter of choosing the right way to perform the sorting. Seealso CListCtrland Sorting Rows.


我们还可以选择覆盖CGridListCtrlEx :: SortColumn ( )方法。那么,是选择正确的方式进行排序的只是一个问题。另请参阅CListCtrl的和行排序。

ShowingTooltip  显示提示

By default, the CGridListCtrlEx willjust display the cell contents as tooltip. If we want to display somethingdifferent in the tooltip, then we can override the CGridListCtrlEx::OnDisplayCellTooltip() method.

默认情况下, CGridListCtrlEx只会显示单元格内容的提示。如果我们要显示不同的东西在提示,那么我们就可以覆盖CGridListCtrlEx ::OnDisplayCellTooltip ( )方法。

FormattingCells/Subitems   格式化单元格/子项

If we want to change theforeground/background color or the font style (bold, italic, underline), thenwe can override the methods CGridListCtrlEx::OnDisplayCellColor() andCGridListCtrlEx::OnDisplayCellFont().


如果我们想改变前景/背景颜色或字体样式(粗体,斜体,下划线) ,那么我们可以覆盖的方法CGridListCtrlEx:: OnDisplayCellColor ( ) andCGridListCtrlEx ::OnDisplayCellFont ( ) 。

 

 Collapse CopyCode

bool MyGridCtrl::OnDisplayCellColor(int nRow, int nCol, COLORREF& textColor, COLORREF& backColor)
{
   if (nRow == 3 && nCol == 3)
   {
      textColor = RGB(0,255,0);
      backColor = RGB(0,0,255);
      return true// I want to override the color of this cell
   }
   return false// Use default color
}

 

DisplayingCell/Subitem Images  显示单元格/子项的图片

The CGridListCtrlEx enablesthe extended style LVS_EX_SUBITEMIMAGES bydefault, but one is still required to attach a CImageList using CListCtrl::SetImageList()

该CGridListCtrlEx使扩展样式LVS_EX_SUBITEMIMAGES默认,但仍然需要使用附加CImageList使用CListCtrl :: SetImageList() 。.

After having attached the images, onecan bind a cell/subitem with an index in the CImageList. This can be done with CGridListCtrlEx::SetCellImage(), or if using I_IMAGECALLBACK thenreturn the image index by overriding CGridListCtrlEx::OnDisplayCellImage().

具有附着的图像以后

,人们可以绑定一个单元格/子项与在CImageList索引。这可以通过CGridListCtrlEx做:: SetCellImage ( ) ,或者如果使用I_IMAGECALLBACK然后通过重写CGridListCtrlEx ::OnDisplayCellImage返回图像索引( ) 。

The CGridListCtrlEx alsoenables the extended style LVS_EX_GRIDLINES bydefault, which can cause subitem images to overlap the grid border. This can besolved by making sure that the image only uses 15 of the 16 pixels (first pixeltransparent).

该CGridListCtrlEx还使扩展样式LVS_EX_GRIDLINES默认,这可能会导致子项的图像到网格边界重叠。这可以通过确保在图像仅使用15的16个象素(第一像素透明)来解决。

When using subitem images and runningthe application on Windows XP or using classic style, it will show a whitebackground when a row is selected. This can be fixed by using CGridRowTraitXP:

当使用分项的图像和运行在Windows XP的应用程序或使用经典的款式,它会显示一个白色背景当选择一排。这可以固定用CGridRowTraitXP :

 Collapse CopyCode

m_ListCtrl.SetDefaultRowTrait(new CGridRowTraitXP);

 

 

Checkbox Support      复选框支持

CListCtrl supports checkboxes for the label column out of the box. Justapply the extended styleLVS_EX_CHECKBOXES:

CListCtrl的支持复选框标签列开箱。只是应用扩展样式LVS_EX_CHECKBOXES :

 Collapse CopyCode

m_ListCtrl.SetExtendedStyle(m_ListCtrl.GetExtendedStyle() | LVS_EX_CHECKBOXES);

Remember not to use InsertHiddenLabelColumn() as it will hide the label column and its checkbox. One can use GetCheck() SetCheck() to retrieve/modify the

checkbox value.

切记不要用InsertHiddenLabelColumn ( ),因为它会隐藏标签栏和其复选框。人们可以使用GetCheck () / SetCheck ()来检索/修改
复选框值。

If wanting to havecheckboxes for multiple columns, then one can use CGridColumnTraitImage (and its specializations):

如果希望有复选框多个列,那么可以使用CGridColumnTraitImage (及其专业) :

 Collapse CopyCode

// Appends the unchecked/checked state images to the list control image list
int nStateImageIdx = CGridColumnTraitImage::AppendStateImages(m_ListCtrl, m_ImageList);
m_ListCtrl.SetImageList(&m_ImageList, LVSIL_SMALL);
// Creates an image column, that can switch between the 2 images
CGridColumnTrait* pTrait = new CGridColumnTraitImage(nStateIdx, 2);
m_ListCtrl.InsertColumnTrait(nCol, title.c_str(), LVCFMT_LEFT, 20, nCol, pTrait);
for(int i=0; i < m_ListCtrl.GetItemCount(); ++i)
         m_ListCtrl.SetCellImage(i, nCol, nStateImageIdx);   // Uncheck item

The label column willautomatically display the image column when assigning an CImageList usingSetImageList(). Itis not possible to disable this behavior, but one can hide the label columnusingInsertHiddenLabelColumn().

使用SetImageList分配一个CImageList时,标签栏会自动显示图像列( ) 。这是不可能禁用这种行为,而是一个可以隐藏使用InsertHiddenLabelColumn ( )的标签列。

 

CGridColumnTraitImage uses the cell image to draw the checkbox, so it is not possibleto have both cell image and checkbox in the same column. To get and set thechecked / unchecked state, one can use GetCellImage() /SetCellImage().

CGridColumnTraitImage使用单元格图像来绘制的复选框,所以它不可能在同一列中两个单元格图像和复选框。要获取和设置选中/取消选中状态,可以使用GetCellImage ( ) / SetCellImage ( ) 。

 

CGridColumnTraitImage supports sorting according to whether the checkbox is enabled.UseCGridColumnTraitImage::SetSortImageIndex() to enable this.

CGridColumnTraitImage支持根据复选框是否启用排序。 UseCGridColumnTraitImage ::SetSortImageIndex ()来实现这一点。

CGridColumnTraitImage also supports toggling of checkboxes for all selected rows. UseCGridColumnTraitImage::SetToggleSelection() to enable this.

CGridColumnTraitImage还支持复选框所有选定行的切换。使用CGridColumnTraitImage ::SetToggleSelection ()来实现这一点.

 

Hyperlinksupport

Hyperlink columns can display the cellcontents as links, which can be clicked and will launch an externalapplications like the default web-browser (http) or email-client (mailto).

The CGridColumnTraitHyperLink allowsone to supply a prefix (and suffix) for the celltext, which allows one to addextra protocol details without it being displayed:

 Collapse CopyCode

CGridColumnTraitHyperLink* pHyperLinkTrait = new CGridColumnTraitHyperLink;
pHyperLinkTrait->SetShellFilePrefix(_T("http://en.wikipedia.org/wiki/UEFA_Euro_"));
m_ListCtrl.InsertColumnTrait(nCol, title.c_str(), LVCFMT_LEFT, 100, nCol, pHyperLinkTrait);

It is also possible with CGridColumnTraitHyperLink::SetShellApplication() tospecify a custom application to be launched, instead of just the defaultapplication launched based on the protocol prefix.

The hyperlink can also be used tosimulate a button. When clicked it will send a LVN_ENDLABELEDIT notification,which one can treat as a button clicked notification in the parent view.

 

支持超链接

超链接列可以显示单元格内容的链接,可以点击,将启动一个外部应用程序,如默认的Web浏览器( HTTP)或电子邮件客户端(邮寄地址) 。

该CGridColumnTraitHyperLink允许一个供应的CELLTEXT ,它允许一个没有显示其添加额外的协议细节的前缀(和后缀) :

 崩溃|复制代码
CGridColumnTraitHyperLink * pHyperLinkTrait =新CGridColumnTraitHyperLink ;
pHyperLinkTrait- > SetShellFilePrefix ( _T(“ http://en.wikipedia.org/wiki/UEFA_Euro_ ”)) ;
m_ListCtrl.InsertColumnTrait ( NCOL , title.c_str () , LVCFMT_LEFT ,100, NcoI位, pHyperLinkTrait ) ;
也可以用CGridColumnTraitHyperLink:: SetShellApplication ( )来指定一个自定义的应用程序被启动,而不是仅仅基于协议前缀推出的默认应用程序中。

超链接也可以被用来模拟一个按钮。当点击它会发送一个LVN_ENDLABELEDIT通知,其中一个可以当作一个按钮,在父视图点击通知。

ChangingRow Height

The CGridListCtrlEx usescustomdraw, so there are only these available solutions:

·        Assign a CImageList where the image has theheight wanted for the row.

·        Change the font of the gridcontrol, and the row height will follow.CGridListCtrlEx::SetCellMargin() usesthis trick to increase the font of the grid control, while keeping the row fontintact.

·        改变行高

该CGridListCtrlEx使用customdraw ,所以只有这些可用的解决方案:

分配CImageList该图像具有高度通缉行。
更改网格控件的字体和行高将随之而来。 CGridListCtrlEx :: SetCellMargin ()使用这种伎俩来提高网格控件的字体,同时保持该行的字体完好无损。

Changingthe Empty Markup Text

When the CGridListCtrlEx doesn'tcontain any items, it will display markup text to indicate the list is empty.

Use CGridListCtrlEx::SetEmptyMarkupText() tochange this markup text. If providing empty text, then it will behave like anormal CListCtrl.

If using CGridListCtrlGroups, it will instead react to LVN_GETEMPTYMARKUP ifrunning on Windows Vista.

更改空标记文本

当CGridListCtrlEx不包含任何物品,它会显示标记文本,以指示该列表为空。

使用CGridListCtrlEx:: SetEmptyMarkupText ()来改变这种标记文本。如果提供空的文本,那么它会像一个正常的CListCtrl 。

如果使用CGridListCtrlGroups,这反而反应,如果在Windows Vista上运行LVN_GETEMPTYMARKUP 。

Load andSave Column Width and Position

CViewConfigSectionWinApp provides the ability tostore the width, position and whether columns are shown. After having added allavailable columns to the CGridListCtrlEx, assign an instance ofCViewConfigSectionWinApp using CGridListCtrlEx::SetupColumnConfig() and it will restore the lastsaved column configuration through CWinApp.

 Collapse CopyCode

m_ListCtrl.SetupColumnConfig(new CViewConfigSectionWinApp("MyList"));

If using CGridListCtrlEx several places in yourapplication, then one should ensure creation of a uniqueCViewConfigSectionWinApp for each place.

加载和保存列宽度和位置

CViewConfigSectionWinApp提供以存储的宽度,位置的能力和列​​是否被示出。在已经添加了所有可用列的CGridListCtrlEx ,分配CViewConfigSectionWinApp使用CGridListCtrlEx ::SetupColumnConfig ( )的一个实例,它会通过的CWinApp恢复上次保存的列配置。

 崩溃|复制代码
m_ListCtrl.SetupColumnConfig (新CViewConfigSectionWinApp ( “的MyList ”));
如果使用CGridListCtrlEx几个地方在你的应用程序,那么应该确保创造一个独特的CViewConfigSectionWinApp每个地方。

OLE Dragand Drop

CGridListCtrlEx can both work as an OLE dragsource and an OLE drop target. This allows drag operations between the CGridListCtrlEx and other windows andapplications.

CGridListCtrlEx supports reordering of rowswhen doing internal drag and drop. This is implemented using a special sortoperation, so items are not deleted/inserted.

To implement your own special behaviorfor a drop operation, either override OnDropSelf() orOnDropExternal() depending on what situationyou want to handle.

To control what is placed in thedrag-source when a drag is initiated, override OnDisplayToDragDrop().

OLE拖放

CGridListCtrlEx既可以工作,作为一个OLE拖动源和OLE拖放目标。这允许CGridListCtrlEx和其它窗口和应用程序之间的拖动操作。

CGridListCtrlEx支持行重新排序做内部拖放时。这是通过使用一种特殊的操作实现的,所以物品不会被删除/插入。

要实现一个拖放操作自己的特殊的行为,无论是覆盖OnDropSelf ( )或OnDropExternal( ),取决于要处理什么样的情况。

来控制被放置在拖动源时,启动一拖,覆盖OnDisplayToDragDrop ( ) 。

HowDoes the CGridColumnTrait Work

CGridListCtrlEx tries to keep away from allthe nasty details about how to display and edit data. These things are insteadhandled by the CGridColumnTrait class, and if we want tomodify how data is displayed, then it is "just" a matter of creatinga new CGridColumnTrait class.

When inserting a column, we can assign a CGridColumnTrait to the column. The CGridListCtrlEx will activate theappropriate CGridColumnTrait when we need to draw a cellin that column, or edit a cell in the column.

The CGridColumnTrait includes some specialmembers known as meta-data. These members can be used by your own class when itderives from CGridListCtrlEx, so we can easily add extra properties to a column.

When inheriting from CGridColumnTrait, we must consider the following:

·        If performing customdrawing, we must also handle the selection and focus coloring.

·        If performing editing, wemust ensure that the editor closes when it loses focus, and also sends aLVN_ENDLABELEDIT message when the edit is complete.

·        怎样CGridColumnTrait工作
CGridListCtrlEx试图远离所有关于如何显示和编辑数据讨厌的细节。这些东西是不是由CGridColumnTrait类处理,如果我们要修改数据是如何显示的,那么它是创建一个新的CGridColumnTrait类的“公正”的问题。

当插入一列,我们可以指定一个CGridColumnTrait到柱上。该CGridListCtrlEx将激活相应的CGridColumnTrait当我们需要绘制一个单元格的列或编辑在列的单元格。

该CGridColumnTrait包括被称为元数据的一些特殊成员。这些成员可以使用自己的类时,它从CGridListCtrlEx派生,所以我们可以额外的属性到列轻松添加。

当从CGridColumnTrait继承,我们必须考虑以下几点:

如果执行自定义绘制,我们还必须处理的选择和重点色。
如果执行编辑,我们必须确保,当它失去焦点,同时也发送LVN_ENDLABELEDIT消息时,编辑完成后,编辑器关闭。

·        

HowDoes the CGridRowTrait Work

It is based on the same idea as CGridColumnTrait butoperates at row level instead of column level. This is useful for situationswhere one has to modify the display behavior of all columns.

怎样CGridRowTrait工作
它是基于相同的想法作为CGridColumnTrait但操作在水平行,而不是列的水平。这对于情况1具有修改所有列的显示行为是有用的。

Usingthe Code

The source code includes the followingclasses:

·        CGridListCtrlEx - Thespecialized CListCtrl

·        CGridListCtrlGroups CGridListCtrlEx extended with support forgrouping

·        CGridColumnTrait -Specifies the interface of a column-trait

o    CGridColumnTraitText -Implements cell formatting

§  CGridColumnTraitImage -Implements cell editing by switching between images (can mimic a checkbox)

§  CGridColumnTraitEdit -Implements cell editing with CEdit

§  CGridColumnTraitCombo -Implements cell editing with CComboBox

§  CGridColumnTraitDateTime -Implements cell editing with CDateTimeCtrl

§  CGridColumnTraitHyperLink -Implements cell behavior as hyperlinks

·        CGridRowTrait -Specifies the interface of a row trait

o    CGridRowTraitText - Implements row formatting

o    CGridRowTraitXP - Implements drawing ofsubitem image background when using classic- or XP-style

·        CViewConfigSection -Abstract interface for persisting column setup

o    CViewConfigSectionWinApp -Implements the interface and can switch between multiple column setups.

·        使用代码
源代码包括以下类:

CGridListCtrlEx - 该专业的CListCtrl
CGridListCtrlGroups - CGridListCtrlEx扩展与分组支持
CGridColumnTrait - 指定列性状的接口
CGridColumnTraitText - 实现单元格格式
CGridColumnTraitImage - 通过图像间切换(可以模仿一个复选框)实现单元格编辑
CGridColumnTraitEdit - 实现单元格编辑与CEdit的
CGridColumnTraitCombo - 实现单元格编辑与CComboBox快速
CGridColumnTraitDateTime - 实现单元格编辑与CDateTimeCtrl
CGridColumnTraitHyperLink - 实现细胞的行为作为超链接
CGridRowTrait - 指定一排性状的接口
CGridRowTraitText - 实现连续格式
CGridRowTraitXP - 实现了分项图像背景使用classic-或XP风格的绘画时,
CViewConfigSection - 抽象接口,坚持栏设置
CViewConfigSectionWinApp - 实现了接口,可以多列设置之间进行切换。

ThingsTo Do

The CGridListCtrlEx triesto stay away from performing any drawing itself. This means that the followingfeatures/bugs will not get that much attention:

·        Support for progress bar -Requires a CGridColumnTrait class that draws the entirecell.

Implementing a CGridColumnTrait classthat draws the entire cell could probably be done by stealing/borrowing somecode from ListCtrl- A WTL List Control with Windows Vista Style Item Selection.

Contributions to this project are verywelcome.

可以做的事
该CGridListCtrlEx试图远离执行任何图纸本身。这意味着以下特性/错误不会得到那么多的关注:

支持进度条 - 需要绘制整个单元的CGridColumnTrait类。
一个WTL列表控制与Windows Vista风格项目选择 - 实施,吸引了整个单元的CGridColumnTrait类很可能被窃取/借用的ListCtrl一些代码来完成。

贡献,这个项目都非常欢迎。

History

·        Version 1.0 (2008-09-04)First release

·        Version 1.1 (2008-09-18)

o    Added support for grouping with CGridListCtrlGroups

o    Added CDateTimeCtrl editor

o    Fixed drawing bugs when using Classic- and XP-style

§  Fixed image background color for selected subitems (no longerwhite)

§  Fixed grid border disappearing when scrolling right and left

o    Indicate the list is empty when it contains no items

o    Extended CComboBox editor, so it automaticallyresizes dropdown width to its contents

·        历史
版本1.0 ( 2008-09-04 )首次发行
版本1.1 ( 2008-09-18 )
新增支持与CGridListCtrlGroups分组
添加CDateTimeCtrl编辑器
使用Classic-和XP风格时,固定绘图错误
固定的图像背景颜色选择子项目(不再是白色)
定格边框消失滚动时左右
显示列表为空时,它不包含任何项目
扩展CComboBox快速编辑器,因此它会自动调整大小下拉宽度其内容

  • Version 1.2 (2008-09-24)
    • Replaced the CGridListCtrlXP with CGridRowTraitXP
    • Fixed some reported bugs
  • Version 1.3 (2008-10-09)
    • Fixed extended style when used in CView
    • Fixed positioning of context-menu when using keyboard shortcut (SHIFT+F10)
    • Fixed compiler errors that appeared when using Visual Studio 6 (VC6)
  • Version 1.4 (2008-11-07)
    • Added clipboard support for copying the contents of the selected cell / rows
    • Renamed the "Callback"-functions to "OnDisplay", as it resembles the MFC naming convention
    • Fixed some reported bugs
  • Version 1.5 (2009-03-29)
    • Added column manager CGridColumnManager
    • Added support for groups on VC6 with platform SDK
    • Added sample projects for the different versions of Visual Studio
    • Improved documentation through Doxygen comments

·        版本1.2 ( 2008-09-24 )
取代了CGridListCtrlXP与CGridRowTraitXP
修正了一些错误报道
版本1.3 ( 2008-10-09 )
固定扩展样式的CView中使用时,
上下文菜单中使用键盘快捷键时,固定定位( SHIFT + F10 )
固定的编译器错误是使用Visual Studio 6时出现( VC6 )
版本1.4 ( 2008-11-07 )
复制选定单元格/行的内容添加剪贴板支持
改名为“回调” -functions为“定义onDisplay ” ,因为它类似于MFC命名惯例
修正了一些错误报道
版本1.5 ( 2009-03-29 )
添加的列经理CGridColumnManager
增加了对平台的SDK上VC6组支持
添加样本项目的不同版本的Visual Studio
通过Doxygen的意见改进文档

  • Version 1.6 (2009-09-13)
    • Added OLE drag and drop support
    • Added support for checkbox style LVS_EX_CHECKBOX when using LVS_OWNERDATA
    • Added better support for keyboard search with LVS_OWNERDATA
    • Fixed several bugs
  • Version 1.7 (2009-12-12)
    • Added CGridColumnTraitImage, that can mimic checkbox editing for any column
    • Renamed OnTraitEditBegin() to OnEditBegin()
    • Renamed OnTraitEditComplete() to OnEditComplete()
    • Renamed OnTraitCustomDraw() to OnCustomDrawCell()
    • Fixed several bugs (Mostly row and cell coloring)
  • Version 1.8 (2010-10-01)
    • Made CGridColumnTraitImage a base class for all editor column traits, so they all can mimic checkbox support
    • Implemented multiple selection checkbox support, so checkboxes are flipped for all selected rows
    • Implemented min and max column width through the base column trait
    • Fixed several bugs
  • Version 1.9 (2011-05-30)
    • Changed CGridColumnTrait::OnSortRows to take an LVITEM as argument instead of character strings
    • Renamed CGridColumnConfig to CViewConfigSection
    • Removed CGridColumnManager and moved LoadState/SaveState into CGridListCtrlEx(breaking change)
  • Version 2.0 (2012-05-01)
    • Added copy/paste support for CDateTimeCtrl editor (DTS_APPCANPARSE)
    • When having grouped by column, then column header click now sorts instead of grouping by column
    • Changed the row sorting to be case insensitive by default
    • Fixed bug where cell editor discarded changes performed using the mouse (copy/paste using context menu)
    • Fixed several compiler warnings, and small bugs

·        版本1.6 ( 2009-09-13 )
添加OLE拖放支持
使用LVS_OWNERDATA时的复选框风格LVS_EX_CHECKBOX新增支持
键盘搜索与LVS_OWNERDATA增加了更好的支持
修正了几个错误
版本1.7 ( 2009-12-12 )
添加CGridColumnTraitImage,可以模仿复选框编辑的任何列
改名OnTraitEditBegin()来OnEditBegin( )
改名OnTraitEditComplete()来OnEditComplete( )
改名OnTraitCustomDraw()来OnCustomDrawCell( )
修正了几个错误(主要排和细胞色素)
版本1.8 ( 2010-10-01 )
做CGridColumnTraitImage所有编辑列特征的基类,所以他们都可以模仿复选框支持
实施多重选择复选框的支持,所以复选框翻转所有选定行
通过基地柱特质实施的最小值和最大值的列宽
修正了几个错误
版本1.9 ( 2011-05-30 )
改变CGridColumnTrait:: OnSortRows采取的LVITEM作为参数,而不是字符串
更名CGridColumnConfig到CViewConfigSection
删除CGridColumnManager和移动LoadState的/ saveState和成CGridListCtrlEx (打破变化)
版本2.0 ( 2012-05-01 )
对于CDateTimeCtrl编辑添加的复制/粘贴支持( DTS_APPCANPARSE )
当已经通过分组列,那么列标题点击排序现在,而不是通过列分组
更改行排序,以区分在默认情况下不区分大小写
使用鼠标进行修正了电池废弃的编辑改动(拷贝/使用上下文菜单中粘贴)
修正了几个编译器警告和小错误

 

·        Version 2.1 (2012-06-20)

o   Fixed bug introduced in 2.0, where grouping of items nolonger worked on WinXP.

o   Improved performance when sorting item groups, especiallyon Vista/Win7+.

o   Added new column trait CGridColumnTraitHyperLink, that candisplay cell text as weblinks. Updated demo application to display the newcolumn type.

o   Added new column trait CGridColumnTraitMultilineEdit, that can editcell text that contains newlines (still displayed in a single line).

o   Fixed several small bugs

·        Version 2.2 (2012-11-11)

o   CGridColumnTraitCombo now has the option to display dropdownon edit begin (SetShowDropDown)

o   All column trait editors now has the option to starteditor on first mouse click (SetSingleClickEdit)

o   CGridColumnTraitHyperLink will sent LVN_ENDLABELEDIT notification toparent on mouse click (Simulates button click)  

o   Checkbox state icon used by subitems has been improved onWindows 7/8 by avoiding image scaling 

o   Fixed several small bugs 

·        版本2.1 ( 2012-06-20 )
在2.0 ,在项目组不再工作在WinXP修正了介绍。
整理项目组时,尤其是在Vista / Win7的+提高了性能。
添加新列特质CGridColumnTraitHyperLink,它可以显示电池的文本为网站链接。更新的演示应用程序,以显示新列的类型。
添加新列特质CGridColumnTraitMultilineEdit,可编辑包含新行单元格文本(仍然显示在单行) 。
修正了几个小错误
版本2.2 ( 2012年11月11日)
CGridColumnTraitCombo现在已经显示在下拉列表编辑选项开始( SetShowDropDown )
所有列特质编辑现在已经开始编辑第一次鼠标点击的选项( SetSingleClickEdit )
CGridColumnTraitHyperLink将发送LVN_ENDLABELEDIT通知家长在点击鼠标(可模拟按钮点击)
采用分项的复选框的状态图标已经在Windows 7/8进行了改进,避免图像缩放
修正了几个小错误

 

License

This article, along with any associatedsource code and files, is licensed under TheCode Project Open License (CPOL)

许可证
这篇文章,以及任何相关的源代码和文件,是根据代码项目开放许可( CPOL )

 

 

0 0
原创粉丝点击