For those who want to very quickly have a pathed version of this code and save some time,
I created a .diff file.
How to merge this patches with a code ?
* Download and install TortoiseSVN http://tortoisesvn.tigris.org/
* Download and unpack Download demo project (v2.26 beta) - 296 Kb
* From installation folder run a TortoiseMerge.exe
* A startup window appear (or run it via File->Open), select Apply Unified diff option
** as diff file select and save code part of this message
** as a target folder select a folder where you unpacked demo project. Clik Ok
* A popup window appear - select all files there (via shift with mouse) and from a context menu select an option "Apply all patches"
* When operation finishes, you will have these fixes merged with the source.
-----
List of changes:
General Paste Unicode Build Fix
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=3202105#xx3202105xx
Solve also:
* Attempt paste into cell with focus but not in edit mode - stange characters
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2052068#xx2052068xx
* How to solve messy code problems such as copy/cut/paste in the cell operation in VS2008 sp1
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=3198723#xx3198723xx
* Fix problem with copy and paste unicode text
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=1446531#xx1446531xx
* Bug about drag & drop(fit only for vc2003+)
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2854440#xx2854440xx
* I found a problem at drag&drop.
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2624428#xx2624428xx
An Assertion in the function void CGridCellCheck::OnClick(CPoint PointCellRelative)
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=3171540#xx3171540xx
Crash in destructor after ordering columns per drag&drop
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=3123995#xx3123995xx
Problem with reordering and sorting.
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2804534#xx2804534xx
Solve also:
* sorting after changing column order
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=1896772#xx1896772xx
Error in GridCell.cpp (inserting new column)
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2799524#xx2799524xx
probably also fix:
*how can i insert a column,please help!
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2795420#xx2795420xx
* InsertColumn failure
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=1775613#xx1775613xx
* InsertColumn() crashes application in 2.26
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=1553874#xx1553874xx
How can I set Particular Cell for Editable True or False
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2754308#xx2754308xx
+ my custom code
Using Check Boxes within MFC Grid Ctrl (how to check state)
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2588308#xx2588308xx
Fails to compile with GRIDCONTROL_NO_CLIPBOARD and GRIDCONTROL_NO_DRAGDROP set
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2414219#xx2414219xx
Solve also:
* #define related to the clipboard
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2125587#xx2125587xx
Grid "Stealing" DTN_DATETIMECHANGE notification
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2302544#xx2302544xx
Fix come from
* Release mouse over control causes notifications without having previously clicked in the control
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=3167336#xx3167336xx
Need help : First Visible Cell !
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2086692#xx2086692xx
Added CTRL-D Functionality
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=2120043#xx2120043xx
How to resize row (example) THANKs for you provide the Cgridctrl,but I meet some error?
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=1994954#xx1994954xx
Bugfix - eating wrong LButtonUp Messages
(also fix for Rclick)
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx?msg=1899540#xx1899540xx
Index: GridCtrl_src/GridCellBase.cpp
===================================================================
--- GridCtrl_src/GridCellBase.cpp (wersja 42)
+++ GridCtrl_src/GridCellBase.cpp (kopia robocza)
@@ -411,42 +411,56 @@
void CGridCellBase::OnMouseEnter()
{
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE0("Mouse entered cell\n");
+#endif
}
void CGridCellBase::OnMouseOver()
{
+#ifdef _DEBUG_MFCGRIDCTRL
+#endif
}
void CGridCellBase::OnMouseLeave()
{
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE0("Mouse left cell\n");
+#endif
}
void CGridCellBase::OnClick( CPoint PointCellRelative)
{
UNUSED_ALWAYS(PointCellRelative);
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE2("Mouse Left btn up in cell at x=%i y=%i\n", PointCellRelative.x, PointCellRelative.y);
+#endif
}
void CGridCellBase::OnClickDown( CPoint PointCellRelative)
{
UNUSED_ALWAYS(PointCellRelative);
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE2("Mouse Left btn down in cell at x=%i y=%i\n", PointCellRelative.x, PointCellRelative.y);
+#endif
}
void CGridCellBase::OnRClick( CPoint PointCellRelative)
{
UNUSED_ALWAYS(PointCellRelative);
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE2("Mouse right-clicked in cell at x=%i y=%i\n", PointCellRelative.x, PointCellRelative.y);
+#endif
}
void CGridCellBase::OnDblClick( CPoint PointCellRelative)
{
UNUSED_ALWAYS(PointCellRelative);
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE2("Mouse double-clicked in cell at x=%i y=%i\n", PointCellRelative.x, PointCellRelative.y);
+#endif
}
Index: GridCtrl_src/GridCtrl.cpp
===================================================================
--- GridCtrl_src/GridCtrl.cpp (wersja 42)
+++ GridCtrl_src/GridCtrl.cpp (kopia robocza)
@@ -241,6 +241,7 @@
m_bAllowColumnResize = TRUE;
m_bSortOnClick = FALSE;
m_bHandleTabKey = TRUE;
+ m_bHandleMoreKeyShortcut = FALSE;
#ifdef _WIN32_WCE
m_bDoubleBuffer = FALSE;
#else
@@ -938,6 +939,10 @@
OnEditPaste();
break;
#endif
+ case 'D':
+ if(!m_bHandleMoreKeyShortcut) break;
+ FillDownAdjacentCells();
+ break;
}
}
@@ -951,7 +956,9 @@
if (nChar == VK_DELETE)
{
+#ifndef GRIDCONTROL_NO_CLIPBOARD
CutSelectedText();
+#endif
}
else if (nChar == VK_DOWN)
{
@@ -1608,7 +1615,7 @@
EraseBkgnd(pDC);
-#ifdef _DEBUG
+#ifdef _DEBUG_MFCGRIDCTRL
LARGE_INTEGER iStartCount;
QueryPerformanceCounter(&iStartCount);
#endif
@@ -1809,7 +1816,7 @@
if (GetVirtualMode())
SendCacheHintToParent(CCellRange(-1,-1,-1,-1));
-#ifdef _DEBUG
+#ifdef _DEBUG_MFCGRIDCTRL
LARGE_INTEGER iEndCount;
QueryPerformanceCounter(&iEndCount);
TRACE1("Draw counter ticks: %d\n", iEndCount.LowPart-iStartCount.LowPart);
@@ -2169,7 +2176,9 @@
}
}
}
+#ifdef _DEBUG_MFCGRIDCTRL
+#endif
if (pDC != NULL)
ReleaseDC(pDC);
@@ -2310,6 +2319,42 @@
}
}
+void CGridCtrl::FillDownAdjacentCells(void)
+{
+ CCellRange cellRange = GetSelectedCellRange();
+ if(!cellRange.IsValid())
+ return;
+ if(cellRange.GetRowSpan()<2)
+ return;
+
+
+
+ CGridCellBase *pCell;
+ int iCol,iRow;
+ CString celltext;
+
+
+ for(iCol = cellRange.GetMinCol(); iCol <= cellRange.GetMaxCol(); iCol++)
+ {
+ pCell = GetCell(cellRange.GetMinRow(), iCol);
+ celltext = pCell->GetText();
+
+
+ for(iRow = cellRange.GetMinRow()+1; iRow <= cellRange.GetMaxRow(); iRow++)
+ {
+
+
+
+ if (pCell->GetRuntimeClass() == GetCell(iRow,iCol)->GetRuntimeClass())
+ ValidateAndModifyCellContents(iRow, iCol, celltext);
+
+ RedrawColumn(iCol);
+ }
+ }
+
+}
+
+
void CGridCtrl::ClearCells(CCellRange Selection)
{
for (int row = Selection.GetMinRow(); row <= Selection.GetMaxRow(); row++)
@@ -2431,16 +2476,16 @@
- LPTSTR szBuffer = new TCHAR[::GlobalSize(hmem)];
+ LPSTR szBuffer = new char[::GlobalSize(hmem)];
if (!szBuffer)
return FALSE;
sf.Read(szBuffer, (UINT)::GlobalSize(hmem));
::GlobalUnlock(hmem);
-
+
- CString strText = szBuffer;
+ CString strText(szBuffer);
delete szBuffer;
@@ -3889,6 +3934,8 @@
END_CATCH
m_nCols++;
+ m_arColOrder.resize(m_nCols);
+ m_arColOrder[m_nCols-1] = m_nCols-1;
SetItemText(0, nColumn, strHeading);
@@ -4040,6 +4087,39 @@
return TRUE;
}
+
+BOOL CGridCtrl::SetItemStateReadOnly(const int nRow, const int nCol,BOOL ReadOnly )
+{
+ if (GetVirtualMode())
+ return FALSE;
+
+
+ CGridCellBase* pCell = GetCell(nRow, nCol);
+ ASSERT(pCell);
+ if (!pCell)
+ return FALSE;
+
+ DWORD dwItemState = pCell->GetState();
+ if(ReadOnly)
+ dwItemState |= GVIS_READONLY;
+ else
+ dwItemState &= ~GVIS_READONLY;
+
+ pCell->SetState(dwItemState);
+
+ return TRUE;
+}
+
+UINT CGridCtrl::GetItemStateReadOnly(const int nRow, const int nCol) const
+{
+ CGridCellBase* pCell = GetCell(nRow, nCol);
+ ASSERT(pCell);
+ if (!pCell)
+ return FALSE;
+
+ return pCell->GetState() & GVIS_READONLY;
+}
+
CGridCellBase* CGridCtrl::CreateCell(int nRow, int nCol)
{
@@ -4097,11 +4177,20 @@
DestroyCell(row, nColumn);
- pRow->RemoveAt(nColumn);
+ pRow->RemoveAt(m_arColOrder[nColumn]);
}
}
- m_arColWidths.RemoveAt(nColumn);
+ m_arColWidths.RemoveAt(m_arColOrder[nColumn]);
+
+ int DEL = m_arColOrder[nColumn];
+ m_arColOrder.erase(m_arColOrder.begin()+nColumn);
+
m_nCols--;
+
+ for(int i = 0; i < m_nCols; i++)
+ if(m_arColOrder[i] > DEL)
+ m_arColOrder[i] = m_arColOrder[i]-1;
+
if (nColumn < m_nFixedCols)
m_nFixedCols--;
@@ -4712,6 +4801,9 @@
{
BOOL bSelected = IsCellSelected(nRow, nCol);
+ if (GetVirtualMode())
+ return FALSE;
+
if (bSelected && !(state & GVIS_SELECTED))
{
@@ -4729,8 +4821,6 @@
m_SelectedCellMap.SetAt(MAKELONG(nRow, nCol), cell);
}
- if (GetVirtualMode())
- return FALSE;
CGridCellBase* pCell = GetCell(nRow, nCol);
ASSERT(pCell);
@@ -5542,6 +5632,32 @@
return IsSelectable() && ((GetItemState(nRow, nCol) & GVIS_SELECTED) == GVIS_SELECTED);
}
+int CGridCtrl::GetFirstVisibleRow()
+{
+
+
+ return GetUnobstructedNonFixedCellRange().GetMinRow();
+}
+
+int CGridCtrl::GetLastVisibleRow()
+{
+
+
+ return GetUnobstructedNonFixedCellRange().GetMaxRow();
+}
+
+int CGridCtrl::SetFirstVisibleRow(const int nRow)
+{
+ CCellRange VisibleCells = GetUnobstructedNonFixedCellRange();
+ int iRow;
+ if(nRow > VisibleCells.GetMinRow())
+ iRow = nRow+(VisibleCells.GetMaxRow()-VisibleCells.GetMinRow());
+ else
+ iRow = nRow;
+ EnsureVisible(iRow,0);
+ return iRow;
+}
+
BOOL CGridCtrl::IsCellVisible(CCellID cell)
{
return IsCellVisible(cell.row, cell.col);
@@ -5901,7 +6017,9 @@
void CGridCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE0("CGridCtrl::OnLButtonDblClk\n");
+#endif
CCellID cell = GetCellFromPt(point);
if( !IsValid( cell) )
@@ -6352,7 +6470,15 @@
{
ResetSelectedRange();
+
+
+#ifndef GRIDCONTROL_NO_DRAGDROP
m_MouseMode = MOUSE_PREPARE_DRAG;
+#else
+#ifdef _DEBUG_MFCGRIDCTRL
+ TRACE0("GridCtrl: OnLButtonDown: Check if not setting mouse mode is ok.");
+#endif
+#endif
m_CurCol = m_LeftClickDownCell.col;
}
}
@@ -6375,6 +6501,9 @@
CWnd::OnLButtonUp(nFlags, point);
+ if(m_bLMouseButtonDown==FALSE)
+ return;
+
m_bLMouseButtonDown = FALSE;
#ifndef _WIN32_WCE_NO_CURSOR
@@ -6463,7 +6592,7 @@
Invalidate();
}
}
- else
+ else if(m_MouseMode != MOUSE_NOTHING)
{
SendMessageToParent(m_idCurrentCell.row, m_idCurrentCell.col, GVN_SELCHANGED);
@@ -6495,7 +6624,9 @@
m_bRMouseButtonDown = TRUE;
#ifdef GRIDCONTROL_USE_TITLETIPS
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE0("Hiding TitleTip\n");
+#endif
m_TitleTip.Hide();
#endif
}
@@ -6506,6 +6637,8 @@
{
CWnd::OnRButtonUp(nFlags, point);
+ if(m_bRMouseButtonDown==FALSE)
+ return;
m_bRMouseButtonDown = FALSE;
CCellID FocusCell;
@@ -7146,8 +7279,15 @@
CString strRight;
+
+#ifndef GRIDCONTROL_NO_CLIPBOARD
COleDateTime t = COleDateTime::GetCurrentTime();
strRight = t.Format(_T("%c"));
+#else
+ CTime t;
+ t.GetCurrentTime();
+ strRight = t.Format(_T("%c"));
+#endif
CRect rc(pInfo->m_rectDraw);
Index: GridCtrl_src/GridCtrl.h
===================================================================
--- GridCtrl_src/GridCtrl.h (wersja 42)
+++ GridCtrl_src/GridCtrl.h (kopia robocza)
@@ -25,6 +25,13 @@
#if !defined(AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
#define AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_
++
++#ifdef _DEBUG
+#define _DEBUG_MFCGRIDCTRL
+#endif
+
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
@@ -324,6 +331,8 @@
BOOL GetHeaderSort() const { return m_bSortOnClick; }
void SetHandleTabKey(BOOL bHandleTab = TRUE) { m_bHandleTabKey = bHandleTab; }
BOOL GetHandleTabKey() const { return m_bHandleTabKey; }
+ void SetHandleMoreKeyShortcut(const BOOL bMoreKeyShortcut = TRUE) { m_bHandleMoreKeyShortcut = bMoreKeyShortcut; }
+ BOOL GetHandleMoreKeyShortcut() const { return m_bHandleMoreKeyShortcut; }
void SetDoubleBuffering(BOOL bBuffer = TRUE) { m_bDoubleBuffer = bBuffer; }
BOOL GetDoubleBuffering() const { return m_bDoubleBuffer; }
void EnableTitleTips(BOOL bEnable = TRUE) { m_bTitleTips = bEnable; }
@@ -399,6 +408,8 @@
BOOL SetCellType(int nRow, int nCol, CRuntimeClass* pRuntimeClass);
BOOL SetDefaultCellType( CRuntimeClass* pRuntimeClass);
+ BOOL SetItemStateReadOnly(const int nRow, const int nCol, BOOL ReadOnly = TRUE);
+ UINT GetItemStateReadOnly(const int nRow, const int nCol) const;
@@ -434,6 +445,9 @@
BOOL IsCellEditable(CCellID &cell) const;
BOOL IsCellSelected(int nRow, int nCol) const;
BOOL IsCellSelected(CCellID &cell) const;
+ int GetFirstVisibleRow();
+ int GetLastVisibleRow();
+ int SetFirstVisibleRow(const int nRow);
@@ -584,6 +598,8 @@
void ValidateAndModifyCellContents(int nRow, int nCol, LPCTSTR strText);
+ void FillDownAdjacentCells(void);
+
@@ -649,6 +665,7 @@
BOOL m_bFixedRowSelection, m_bFixedColumnSelection;
BOOL m_bSortOnClick;
BOOL m_bHandleTabKey;
+ BOOL m_bHandleMoreKeyShortcut;
BOOL m_bDoubleBuffer;
BOOL m_bTitleTips;
int m_nBarState;
@@ -897,7 +914,7 @@
if (!pRow) return FALSE;
pCell->SetCoords( nRow, nCol);
- pRow->SetAt(nCol, pCell);
+ pRow->SetAt(m_arColOrder[nCol], pCell);
return TRUE;
}
Index: GridCtrl_src/GridDropTarget.cpp
===================================================================
--- GridCtrl_src/GridDropTarget.cpp (wersja 42)
+++ GridCtrl_src/GridDropTarget.cpp (kopia robocza)
@@ -111,7 +111,9 @@
DROPEFFECT CGridDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject,
DWORD dwKeyState, CPoint point)
{
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE(_T("In CGridDropTarget::OnDragEnter\n"));
+#endif
ASSERT(m_pGridCtrl);
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
@@ -122,7 +124,9 @@
void CGridDropTarget::OnDragLeave(CWnd* pWnd)
{
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE(_T("In CGridDropTarget::OnDragLeave\n"));
+#endif
ASSERT(m_pGridCtrl);
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
@@ -132,7 +136,9 @@
DROPEFFECT CGridDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject,
DWORD dwKeyState, CPoint point)
{
+#ifdef _DEBUG_MFCGRIDCTRL
+#endif
ASSERT(m_pGridCtrl);
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
@@ -144,7 +150,9 @@
BOOL CGridDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point)
{
+#ifdef _DEBUG_MFCGRIDCTRL
TRACE(_T("In CGridDropTarget::OnDrop\n"));
+#endif
ASSERT(m_pGridCtrl);
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
Index: GridCtrlDemo.rc
===================================================================
--- GridCtrlDemo.rc (wersja 42)
+++ GridCtrlDemo.rc (kopia robocza)
@@ -32,66 +32,42 @@
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,7,7,20,20
- LTEXT "GridCtrlDemo Version 2.25",IDC_STATIC,40,7,119,8,
- SS_NOPREFIX
+ LTEXT "GridCtrlDemo Version 2.25",IDC_STATIC,40,7,119,8,SS_NOPREFIX
LTEXT "Copyright (c) 1998-2004",IDC_STATIC,40,80,119,8
DEFPUSHBUTTON "OK",IDOK,196,7,32,14,WS_GROUP
- LTEXT "Written by Chris Maunder\nchris@codeproject.com",IDC_STATIC,
- 40,22,97,19
- LTEXT "Based on the original WorldCom grid control written by Joe Willcoxson (chinajoe@bigfoot.com)\nweb: http://user.aol.com/chinajoe/wcmfclib.html",
- IDC_STATIC,40,43,171,29
+ LTEXT "Written by Chris Maunder\nchris@codeproject.com",IDC_STATIC,40,22,97,19
+ LTEXT "Based on the original WorldCom grid control written by Joe Willcoxson (chinajoe@bigfoot.com)\nweb: http://user.aol.com/chinajoe/wcmfclib.html",IDC_STATIC,40,43,171,29
END
IDD_GRIDCTRLDEMO_DIALOG DIALOGEX 0, 0, 399, 251
-STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION |
- WS_SYSMENU | WS_THICKFRAME
+STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "MFC Grid Control Demo"
MENU IDR_MENU
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CONTROL "Custom1",IDC_GRID,"MFCGridCtrl",WS_TABSTOP,7,7,290,190
- CONTROL "Cell 1,1 Normal",IDC_CELL_NORMAL,"Button",
- BS_AUTORADIOBUTTON | WS_GROUP,316,25,74,10
- CONTROL "Cell 1,1 Read Only",IDC_CELL_READONLY,"Button",
- BS_AUTORADIOBUTTON,316,35,74,10
- CONTROL "Cell 1,1 URL",IDC_CELL_URL,"Button",BS_AUTORADIOBUTTON,
- 316,45,74,10
- CONTROL "Cell 1,1 Combo",IDC_CELL_COMBO,"Button",
- BS_AUTORADIOBUTTON,316,56,74,10
- CONTROL "Cell 1,1 Checkbox",IDC_CELL_CHECK,"Button",
- BS_AUTORADIOBUTTON,316,67,74,10
- CONTROL "Cell 1,1 DateTime",IDC_CELL_DATETIME,"Button",
- BS_AUTORADIOBUTTON,316,78,74,10
- CONTROL "Cell 1,1 Numeric",IDC_CELL_NUMERIC,"Button",
- BS_AUTORADIOBUTTON,316,89,74,10
- EDITTEXT IDC_EDIT_ROWS,341,105,51,12,ES_AUTOHSCROLL | ES_NUMBER |
- WS_GROUP
- CONTROL "Spin1",IDC_SPIN_ROW,"msctls_updown32",UDS_SETBUDDYINT |
- UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,381,105,
- 11,13
+ CONTROL "Cell 1,1 Normal",IDC_CELL_NORMAL,"Button",BS_AUTORADIOBUTTON | WS_GROUP,316,25,74,10
+ CONTROL "Cell 1,1 Read Only",IDC_CELL_READONLY,"Button",BS_AUTORADIOBUTTON,316,35,74,10
+ CONTROL "Cell 1,1 URL",IDC_CELL_URL,"Button",BS_AUTORADIOBUTTON,316,45,74,10
+ CONTROL "Cell 1,1 Combo",IDC_CELL_COMBO,"Button",BS_AUTORADIOBUTTON,316,56,74,10
+ CONTROL "Cell 1,1 Checkbox",IDC_CELL_CHECK,"Button",BS_AUTORADIOBUTTON,316,67,74,10
+ CONTROL "Cell 1,1 DateTime",IDC_CELL_DATETIME,"Button",BS_AUTORADIOBUTTON,316,78,74,10
+ CONTROL "Cell 1,1 Numeric",IDC_CELL_NUMERIC,"Button",BS_AUTORADIOBUTTON,316,89,74,10
+ EDITTEXT IDC_EDIT_ROWS,341,105,51,12,ES_AUTOHSCROLL | ES_NUMBER | WS_GROUP
+ CONTROL "Spin1",IDC_SPIN_ROW,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,381,105,11,13
EDITTEXT IDC_EDIT_COLS,341,118,51,12,ES_AUTOHSCROLL | ES_NUMBER
- CONTROL "Spin2",IDC_SPIN_COL,"msctls_updown32",UDS_SETBUDDYINT |
- UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,381,119,
- 11,12
- EDITTEXT IDC_EDIT_FIXROWS,341,130,51,12,ES_AUTOHSCROLL |
- ES_NUMBER
- CONTROL "Spin1",IDC_SPIN_FIXROW,"msctls_updown32",
- UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
- UDS_ARROWKEYS,381,132,11,13
- EDITTEXT IDC_EDIT_FIXCOLS,341,143,51,12,ES_AUTOHSCROLL |
- ES_NUMBER
- CONTROL "Spin2",IDC_SPIN_FIXCOL,"msctls_updown32",
- UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |
- UDS_ARROWKEYS,381,143,11,12
+ CONTROL "Spin2",IDC_SPIN_COL,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,381,119,11,12
+ EDITTEXT IDC_EDIT_FIXROWS,341,130,51,12,ES_AUTOHSCROLL | ES_NUMBER
+ CONTROL "Spin1",IDC_SPIN_FIXROW,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,381,132,11,13
+ EDITTEXT IDC_EDIT_FIXCOLS,341,143,51,12,ES_AUTOHSCROLL | ES_NUMBER
+ CONTROL "Spin2",IDC_SPIN_FIXCOL,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,381,143,11,12
PUSHBUTTON "Cancel",IDCANCEL,340,7,52,11
LTEXT "Rows",IDC_STATIC,318,108,22,12
LTEXT "Cols",IDC_STATIC,321,121,18,12
LTEXT "Fixed Rows",IDC_STATIC,301,133,37,12
LTEXT "Fixed Cols",IDC_STATIC,303,146,36,12
- SCROLLBAR IDC_SIZEBOX,384,239,15,12,SBS_SIZEBOXBOTTOMRIGHTALIGN |
- SBS_SIZEBOX | SBS_SIZEGRIP
- EDITTEXT IDC_TRACE,7,200,290,47,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL
+ SCROLLBAR IDC_SIZEBOX,384,239,15,12,SBS_SIZEBOXBOTTOMRIGHTALIGN | SBS_SIZEBOX | SBS_SIZEGRIP
+ EDITTEXT IDC_TRACE,7,200,290,47,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL
PUSHBUTTON "Clear Trace Window",IDC_CLEARTRACE,316,161,79,14
END
@@ -238,10 +214,8 @@
POPUP "&Cell Selecting"
BEGIN
MENUITEM "Allow Cell &Selection", IDC_ALLOW_SELECTION
- MENUITEM "Select Row on fixed cell click",
- IDC_FIXEDROW_SELECTION
- MENUITEM "Select Column on fixed cell click",
- IDC_FIXEDCOL_SELECTION
+ MENUITEM "Select Row on fixed cell click", IDC_FIXEDROW_SELECTION
+ MENUITEM "Select Column on fixed cell click", IDC_FIXEDCOL_SELECTION
MENUITEM "Single Column Selection &Mode", IDC_SINGLECOLSELMODE
END
POPUP "Cell &Sizing"
@@ -263,18 +237,24 @@
MENUITEM "Insert &Row at Cursor", IDC_INSERT_ROW
MENUITEM "&Delete Row at Cursor", IDC_DELETE_ROW
MENUITEM SEPARATOR
+ MENUITEM "Insert Column at Cursor", 33050
+ MENUITEM "Delete Column at Cursor", IDC_DELETE_COLUMN
+ MENUITEM SEPARATOR
MENUITEM "Set Focus to cell (1,1)", IDC_SET_FOCUS
MENUITEM SEPARATOR
MENUITEM "Change &Font...", IDC_FONT_BUTTON
+ MENUITEM "Resize Row 2", ID_RESIZEROW2
MENUITEM "Hide Row 2, column 2", ID_HIDE2NDROWCOLUMN
END
POPUP "Grid &Options"
BEGIN
MENUITEM "Allow &Editing", IDC_EDITABLE
+ MENUITEM "Allow Column reordering", IDC_COLUMNSMOVEABLE
MENUITEM "Enable &TitleTips", IDC_TITLETIPS
MENUITEM "Track Focus &Cell", IDC_TRACKFOCUS
MENUITEM "&Frame Focus Cell", IDC_FRAMEFOCUS
MENUITEM "&Sort on Header Click", IDC_HEADERSORT
+ MENUITEM "Handle more key shourtcut", IDC_HANDLEMOREKEYSHOURTCUT
MENUITEM SEPARATOR
MENUITEM "Fixed Cells &Italic", IDC_ITALICS
MENUITEM "Fixed cells have &Vertical Text", IDC_VERTICAL_TEXT
Index: GridCtrlDemoDlg.cpp
===================================================================
--- GridCtrlDemoDlg.cpp (wersja 42)
+++ GridCtrlDemoDlg.cpp (kopia robocza)
@@ -65,6 +65,8 @@
m_bRejectEditAttempts = TRUE;
m_bRejectEditChanges = TRUE;
m_bRow2Col2Hidden = FALSE;
+ m_bAllowColumnReorder = false;
+ m_bHandleMoreKeyShourcut = FALSE;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
@@ -161,6 +163,11 @@
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCopyOrCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
#endif
+ ON_COMMAND(IDC_DELETE_COLUMN, OnDeleteColumn)
+ ON_COMMAND(IDC_INSERT_COLUMN, OnInsertColumn)
+ ON_COMMAND(IDC_COLUMNSMOVEABLE, OnColumnsmoveable)
+ ON_COMMAND(IDC_HANDLEMOREKEYSHOURTCUT, OnHandlemorekeyshourtcut)
+ ON_COMMAND(ID_RESIZEROW2, OnResizeRowFromCode)
END_MESSAGE_MAP()
@@ -716,6 +723,15 @@
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
Trace(_T("Clicked on row %d, col %d\n"), pItem->iRow, pItem->iColumn);
+
+
+ CGridCellBase *pCell = m_Grid.GetCell(pItem->iRow, pItem->iColumn);
+ if( pCell->GetRuntimeClass() == RUNTIME_CLASS(CGridCellCheck) ){
+ if( ((CGridCellCheck*) pCell)->GetCheck() ){
+ Trace(_T(" Checkbox in the cell is checked\n"));
+ }else
+ Trace(_T(" Checkbox in the cell is unchecked\n"));
+ }
}
void CGridCtrlDemoDlg::OnExpandToFit()
@@ -898,6 +914,9 @@
m_Grid.AllowReorderColumn(m_bCallback!=0);
m_Grid.EnableDragRowMode(m_bCallback!=0);
m_Grid.SetVirtualCompare(VirtualCompare);
+ m_Grid.AllowReorderColumn(m_bAllowColumnReorder);
+ m_bHandleMoreKeyShourcut = FALSE;
+ m_Grid.SetHandleMoreKeyShortcut(m_bHandleMoreKeyShourcut);
}
CATCH (CMemoryException, e)
{
@@ -1041,6 +1060,8 @@
GetMenu()->CheckMenuItem(IDC_EDITING_REJECT_ATTEMPT, MF_BYCOMMAND | (m_bRejectEditAttempts)? MF_CHECKED: MF_UNCHECKED);
GetMenu()->CheckMenuItem(IDC_EDITING_REJECT_CHANGE, MF_BYCOMMAND | (m_bRejectEditChanges)? MF_CHECKED: MF_UNCHECKED);
GetMenu()->CheckMenuItem(ID_HIDE2NDROWCOLUMN, MF_BYCOMMAND | (m_bRow2Col2Hidden)? MF_CHECKED: MF_UNCHECKED);
+ GetMenu()->CheckMenuItem(IDC_COLUMNSMOVEABLE, MF_BYCOMMAND | (m_bAllowColumnReorder)? MF_CHECKED: MF_UNCHECKED);
+ GetMenu()->CheckMenuItem(IDC_HANDLEMOREKEYSHOURTCUT, MF_BYCOMMAND | (m_bHandleMoreKeyShourcut)? MF_CHECKED: MF_UNCHECKED);
#endif
}
@@ -1165,3 +1186,45 @@
m_Grid.Refresh();
UpdateMenuUI();
}
+
+void CGridCtrlDemoDlg::OnDeleteColumn()
+{
+ int nCol = m_Grid.GetFocusCell().col;
+ if (nCol >= 0)
+ {
+ m_Grid.DeleteColumn(nCol);
+ m_Grid.Invalidate();
+ }
+}
+
+void CGridCtrlDemoDlg::OnInsertColumn()
+{
+ int nCol = m_Grid.GetFocusCell().col;
+ if (nCol >= 0)
+ {
+ m_Grid.InsertColumn(_T("Newest Col"),1|4|32,nCol+1);
+ m_Grid.Invalidate();
+ }
+}
+
+void CGridCtrlDemoDlg::OnColumnsmoveable()
+{
+ m_bAllowColumnReorder = !m_bAllowColumnReorder;
+ m_Grid.AllowReorderColumn(m_bAllowColumnReorder);
+ UpdateMenuUI();
+}
+
+void CGridCtrlDemoDlg::OnHandlemorekeyshourtcut()
+{
+ m_bHandleMoreKeyShourcut = !m_bHandleMoreKeyShourcut;
+ m_Grid.SetHandleMoreKeyShortcut(m_bHandleMoreKeyShourcut);
+ UpdateMenuUI();
+}
+
+void CGridCtrlDemoDlg::OnResizeRowFromCode()
+{
+ m_Grid.SetRowHeight(2, 60);
+
+ m_Grid.RedrawWindow();
+
+}
Index: GridCtrlDemoDlg.h
===================================================================
--- GridCtrlDemoDlg.h (wersja 42)
+++ GridCtrlDemoDlg.h (kopia robocza)
@@ -54,6 +54,9 @@
BOOL m_bRejectEditAttempts;
BOOL m_bRejectEditChanges;
BOOL m_bRow2Col2Hidden;
+ bool m_bAllowColumnReorder;
+ BOOL m_bHandleMoreKeyShourcut;
+
CGridCtrl m_Grid;
CSize m_OldSize;
@@ -149,6 +152,11 @@
#endif
public:
afx_msg void OnHide2ndrowcolumn();
+ afx_msg void OnDeleteColumn();
+ afx_msg void OnInsertColumn();
+ afx_msg void OnColumnsmoveable();
+ afx_msg void OnHandlemorekeyshourtcut();
+ afx_msg void OnResizeRowFromCode();
};
Index: NewCellTypes/GridCellCheck.cpp
===================================================================
--- NewCellTypes/GridCellCheck.cpp (wersja 42)
+++ NewCellTypes/GridCellCheck.cpp (kopia robocza)
@@ -108,6 +108,8 @@
CCellID cell = GetGrid()->GetCellFromPt(PointCellRelative);
+ if(!cell.IsValid())
+ return;
if (!GetGrid()->IsCellEditable(cell))
return;
Index: resource.h
===================================================================
--- resource.h (wersja 42)
+++ resource.h (kopia robocza)
@@ -72,13 +72,23 @@
#define IDC_EXPAND_USE_FIXED 33045
#define IDC_EDITING_REJECT_ATTEMPT 33046
#define IDC_EDITING_REJECT_CHANGE 33047
+#define ID_Menu 33048
+#define IDC_DELETE_COLUMN 33049
+#define IDC_INSERT_COLUMN 33050
+#define IDC_MOVEABLECOLUMN 33051
+#define IDC_COLUMNSMOVEABLE 33052
+#define ID_GRIDOPTIONS_HANDLEMOREKEYSHOURTCUT 33053
+#define ID_HANDLEMOREKEYSHOURTCUT 33054
+#define IDC_HANDLEMOREKEYSHOURTCUT 33055
+#define ID_GRIDOPERATIONS_RESIZEROW2 33056
+#define ID_RESIZEROW2 33057
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 134
-#define _APS_NEXT_COMMAND_VALUE 33048
+#define _APS_NEXT_COMMAND_VALUE 33058
#define _APS_NEXT_CONTROL_VALUE 1044
#define _APS_NEXT_SYMED_VALUE 101
#endif
I hope, that my patch will be useful for another MFC programmer like this grid is usefull for me. It is really good piece of small, but very useful code
|