• 大小: 6.01MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-02
  • 语言: 其他
  • 标签: list  

资源简介

一个很好的开源代码,实现了listctrl列表项的 edit、combobox等功能

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “CGridColumnTraitCombo.h“

#include “CGridColumnTraitVisitor.h“
#include “CGridListCtrlEx.h“

//------------------------------------------------------------------------
// CGridColumnTraitCombo
//------------------------------------------------------------------------
CGridColumnTraitCombo::CGridColumnTraitCombo()
:m_MaxItems(7)
m_MaxWidth(200)
m_ComboBoxstyle(WS_VSCROLL | WS_HSCROLL | CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_NOINTEGRALHEIGHT)
m_pComboBox(NULL)
{}

void CGridColumnTraitCombo::Accept(CGridColumnTraitVisitor& visitor)
{
visitor.Visit(*this);
}

void CGridColumnTraitCombo::SetMaxItems(int items)
{
m_MaxItems = items;
}

int CGridColumnTraitCombo::GetMaxItems() const
{
return m_MaxItems;
}

void CGridColumnTraitCombo::SetMaxWidth(int width)
{
m_MaxWidth = width;
}

int CGridColumnTraitCombo::GetMaxWidth() const
{
return m_MaxWidth;
}

void CGridColumnTraitCombo::Setstyle(DWORD dwstyle)
{
m_ComboBoxstyle = dwstyle;
}

DWORD CGridColumnTraitCombo::Getstyle() const
{
return m_ComboBoxstyle;
}

CComboBox* CGridColumnTraitCombo::CreateComboBox(CGridListCtrlEx& owner int nRow int nCol const CRect& rect)
{
CComboBox* pComboBox = new CGridEditorComboBox(nRow nCol m_MaxWidth);
VERIFY( pComboBox->Create( WS_CHILD | m_ComboBoxstyle rect &owner 0) );

// Configure font
pComboBox->SetFont(owner.GetCellFont());
return pComboBox;
}

CWnd* CGridColumnTraitCombo::OnEditBegin(CGridListCtrlEx& owner int nRow int nCol)
{
// Get position of the cell to edit
CRect rcItem = GetCellEditRect(owner nRow nCol);
int requiredHeight = GetCellFontHeight(owner);

// Expand the size of the ComboBox according to max-elements
CRect rcFinalSize = rcItem;
rcFinalSize.bottom += rcItem.Height() + requiredHeight * m_MaxItems;

// Create edit control to edit the cell
// - Stores the pointer so elements can be dynamically added later
m_pComboBox = CreateComboBox(owner nRow nCol rcFinalSize);
VERIFY(m_pComboBox!=NULL);

// Add all items to list
if (m_ComboList.GetSize()>0)
{
LoadList(m_ComboList -1);

// Guess the currently selected item in the list
CString item = owner.GetItemText(nRow nCol);
int nCurSel = m_pComboBox->FindString(-1 item);
if (nCurSel!=-1)
m_pComboBox->SetCurSel(nCurSel);
else
m_pComboBox->SetWindowText(item);
}
else
{
CString item = owner.GetItemText(nRow nCol);
m_pComboBox->SetWindowText(item);
}

// Resize combobox according to element count
VERIFY( owner.GetCellRect(nRow nCol LVIR_LABEL rcFinalSize) );
rcFinalSize.bottom += rcItem.Height() + requiredHeight * min(m_MaxItems m_pComboBox->GetCount() + 1);
m_pComboBox->SetWindowPos(NULL // not relative to any other windows
0 0 // TopLeft corner doesn‘t change
rcFinalSize.Width() rcFinalSize.Height()   // existing width new height
SWP_NOMOVE | SWP_NOZORDER // don‘t move bo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    .......      2679  2008-09-11 11:05  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTrait.h

    .......      9691  2008-10-21 13:11  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitCombo.cpp

    .......      2773  2008-09-18 10:16  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitCombo.h

    .......      4461  2008-10-21 13:11  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitDateTime.cpp

    .......      1723  2008-09-11 11:05  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitDateTime.h

    .......      3525  2008-10-21 13:11  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitEdit.cpp

    .......      1329  2008-09-11 11:05  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitEdit.h

    .......      4150  2008-10-29 16:39  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitText.cpp

    .......      1036  2008-09-22 10:56  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitText.h

    .......       827  2008-09-11 11:05  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridColumnTraitVisitor.h

    .......     50616  2008-11-07 12:08  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridListCtrlEx.cpp

    .......      7205  2008-11-07 12:08  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridListCtrlEx.h

    .......     22839  2008-11-03 10:37  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridListCtrlGroups.cpp

    .......      2535  2008-09-22 10:56  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridListCtrlGroups.h

    .......       920  2008-09-22 10:56  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridRowTrait.h

    .......      5331  2008-10-29 16:39  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridRowTraitText.cpp

    .......      1092  2008-09-22 10:56  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridRowTraitText.h

    .......       652  2008-09-22 10:56  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridRowTraitVisitor.h

    .......      4009  2008-09-22 10:56  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridRowTraitXP.cpp

    .......       667  2008-09-22 10:56  CGridListCtrlEx_Demo\CGridListCtrlEx\CGridRowTraitXP.h

     文件   22637568  2013-12-31 15:55  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.ncb

    .......      5764  2008-09-11 11:05  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.rc

     文件        890  2013-07-23 15:03  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.sln

     文件        889  2008-10-08 09:50  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.sln.old

    ..A..H.     21504  2013-12-31 15:55  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.suo

     文件       8076  2013-07-23 15:03  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.vcproj

     文件       8012  2008-11-07 12:11  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.vcproj.8.00.old

     文件       1423  2013-12-31 15:55  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.vcproj.Gaofeng-PC.Administrator.user

     文件       1423  2013-08-12 11:26  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlEx.vcproj.GAOFENG-PC.Gaofeng.user

    .......      1968  2008-09-05 17:48  CGridListCtrlEx_Demo\DemoApplication\CGridListCtrlExApp.cpp

............此处省略27个文件信息

评论

共有 条评论