Originally posted by: Sang-il, Lee
I change HitTestEX and EditSubLabel.
in EditSubLabel(int nItem, int nCol)
....
// Array of Column prder by Sang-il, Lee
for( int i = 0; nCol != piColumnArray[i]; i++ )
// delete Array
CRect rect;
in HitTestEx(CPoint &point, int *col) const
....
// Loop through the visible rows
// Array of Column prder by Sang-il, Lee
for( ;row <=bottom;row++)
return -1;
You can edit "ShowInPlaceList" by "Using a drop down list to change a subitem. (Zafir
Anjum)" same way.
I test this code in Visual C++ 6.0.
When user change column's order by dragging header Control,
Original code has some BUG. Edit Box is not show at correct position or
HitTestEx return incoreect column number.
// Get the column offset
int offset = 0;
INT *piColumnArray = new INT[nColumnCount];
((CListCtrl*)this)->GetColumnOrderArray(piColumnArray);
offset += GetColumnWidth( piColumnArray[i] );
delete [] piColumnArray;
....
// Get the number of columns
CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount();
INT* piColumnArray = new INT[nColumnCount];
((CListCtrl*)this)->GetColumnOrderArray(piColumnArray);
{
// Get bounding rect of item and check whether point falls in it.
CRect rect;
GetItemRect( row, &rect, LVIR_BOUNDS );
if( rect.PtInRect(point) )
{
// Now find the column
for( colnum = 0; colnum < nColumnCount; colnum++ )
{
int colwidth = GetColumnWidth(piColumnArray[colnum]);
if( point.x >= rect.left
&& point.x <= (rect.left + colwidth ) )
{
if( col ) *col = piColumnArray[colnum];
TRACE("Hittestex = %d\n",*col);
delete [] piColumnArray;
return row;
}
rect.left += colwidth;
}
}
}
delete [] piColumnArray;
}
Originally posted by: Sang-il, Lee
I change "OnLButtonDown" like below....
// mb_selectEntireRow is true if use "Entire row select"
CListCtrl::OnLButtonDown(nFlags, point);
int colnum;
If use "Entire row select", that code have some problem.
No one can select any row by clicking subcolumns.
(Go directly to editing mode)
( I don't know whether it has Bugs or not. :-) )
void CAdvListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
int index;
static int lastIndex = -1; // Gendoh
if( ( index = HitTestEx( point, &colnum )) != -1 )
{
UINT flag = LVIS_FOCUSED;
if( (GetItemState( index, flag ) & flag) == flag)
{
// Check first click(Gendoh)
if ((mb_selectEntireRow == true)
&& (index != lastIndex))
{
lastIndex = index;
SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED ,
LVIS_SELECTED | LVIS_FOCUSED);
} else { // Second Click (Original code)
// Add check for LVS_EDITLABELS
if( GetWindowLong(m_hWnd, GWL_STYLE) & LVS_EDITLABELS )
EditSubLabel( index, colnum );
}
} else
SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED ,
LVIS_SELECTED | LVIS_FOCUSED);
}
}
Originally posted by: Orest Kulik
I think I have found solution.
And this causes it:
GetParent() function above ASSERTs error. If you eliminate it, everything will work just the same, but
without errors when debugging.
I use "Selection highlighting of entire row" and "Editable subitems". I have put that
together in the same control. In C++ 5.0 when compiled in the Debug mode, I get ASSERT errors when changing
focus from one list item to another. In the Release mode, there are no errors. If you decide to ignore ASSERT
error in the Debug mode, nothing really happens- everything works fine.
This inline produces the error:
_AFXWIN_INLINE CWnd* CWnd::GetParent() const
{ ASSERT(::IsWindow(m_hWnd)); return CWnd::FromHandle(::GetParent(m_hWnd));
}
void CMyListCtrl::OnSetFocus(CWnd* pOldWnd)
{
CListCtrl::OnSetFocus(pOldWnd);
// check if we are getting focus from label edit box
if(pOldWnd!=NULL && pOldWnd->GetParent()==this)
return;
// repaint items that should change appearance
if((GetStyle() & LVS_TYPEMASK)==LVS_REPORT)
RepaintSelectedItems();
}
Does anybody has idea why that error appears (why there is no valid window handle)?