The CExtGridCell::OnPopupListBoxSelEndOK()
virtual method handles the selection of a list box item and invokes CExtGridWnd::OnGridCellInputComplete()
. We assume the selection of the same list box item can be useful because it can be interpreted as an event for refreshing some data views in your application. For your convenience, we added the following grid cell style which makes all the CExtGridCell***::OnPopupListBoxSelEndOK()
virtual methods not invoking the the CExtGridWnd::OnGridCellInputComplete()
virtual method if the text of the selected list box item is equal to grid cell text:
#define __EGCS_EX_DO_NOT_NOTIFY_LB_SEL_FOR_EQUAL_TEXT 0x00200000L
Here are the modified methods:
bool CExtGridCell::OnPopupListBoxSelEndOK(
CExtPopupInplaceListBox & wndListBox,
CExtGridCell::TrackCellStateInfo_t & _tcsi
)
{
ASSERT_VALID( this );
ASSERT( (&_tcsi.m_cell) == this );
ASSERT_VALID( (&wndListBox) );
ASSERT_VALID( (&_tcsi.m_wndGrid) );
_tcsi.m_nItemNoSelEndOK = wndListBox.GetCurSel();
_tcsi.m_bHelperSelChanged = true;
if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
{
LONG nItemCount = wndListBox.GetCount();
if( nItemCount > 0L )
{
LONG nCurSel = wndListBox.GetCurSel();
if( 0L <= nCurSel && nCurSel < nItemCount )
{
CString strSelLbText;
wndListBox.GetText( nCurSel, strSelLbText );
DWORD dwStyleEx = GetStyleEx();
bool bSendSelEndOkOnEqualText = ( ( dwStyleEx & __EGCS_EX_DO_NOT_NOTIFY_LB_SEL_FOR_EQUAL_TEXT ) != 0 ) ? true : false;
if( ! bSendSelEndOkOnEqualText )
{
CExtSafeString strCurrentText;
TextGet( strCurrentText );
if( strCurrentText == LPCTSTR(strSelLbText) )
return false;
}
if( ! strSelLbText.IsEmpty() )
{
HRESULT hr = OnParseText( LPCTSTR(strSelLbText) );
if( hr == S_OK )
{
TextSet( LPCTSTR(strSelLbText) );
_tcsi.m_wndGrid.OnGridCellInputComplete( *this, _tcsi.m_nColNo, _tcsi.m_nRowNo, _tcsi.m_nColType, _tcsi.m_nRowType, wndListBox.GetSafeHwnd() );
} // if( hr == S_OK )
} // if( ! strSelLbText.IsEmpty() )
} // if( 0L <= nCurSel && nCurSel < nItemCount )
} // if( nItemCount > 0L )
} // if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
return false;
}
bool CExtGridCellComboBox::OnPopupListBoxSelEndOK(
CExtPopupInplaceListBox & wndListBox,
CExtGridCell::TrackCellStateInfo_t & _tcsi
)
{
ASSERT_VALID( this );
ASSERT( (&_tcsi.m_cell) == this );
ASSERT_VALID( (&wndListBox) );
ASSERT_VALID( (&_tcsi.m_wndGrid) );
_tcsi.m_nItemNoSelEndOK = wndListBox.GetCurSel();
_tcsi.m_bHelperSelChanged = true;
if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
{
LONG nItemCount = wndListBox.GetCount();
if( nItemCount > 0L )
{
LONG nCurSel = wndListBox.GetCurSel();
if( 0L <= nCurSel && nCurSel < nItemCount )
{
SetCurSel( nCurSel );
CString strSelLbText;
wndListBox.GetText( nCurSel, strSelLbText );
DWORD dwStyleEx = GetStyleEx();
bool bSendSelEndOkOnEqualText = ( ( dwStyleEx & __EGCS_EX_DO_NOT_NOTIFY_LB_SEL_FOR_EQUAL_TEXT ) != 0 ) ? true : false;
if( ! bSendSelEndOkOnEqualText )
{
CExtSafeString strCurrentText;
TextGet( strCurrentText );
if( strCurrentText == LPCTSTR(strSelLbText) )
return false;
}
TextSet( LPCTSTR(strSelLbText) );
_tcsi.m_wndGrid.OnGridCellInputComplete( *this, _tcsi.m_nColNo, _tcsi.m_nRowNo, _tcsi.m_nColType, _tcsi.m_nRowType, wndListBox.GetSafeHwnd() );
} // if( 0L <= nCurSel && nCurSel < nItemCount )
} // if( nItemCount > 0L )
} // if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
return false;
}
bool CExtGridCellBool::OnPopupListBoxSelEndOK(
CExtPopupInplaceListBox & wndListBox,
CExtGridCell::TrackCellStateInfo_t & _tcsi
)
{
ASSERT_VALID( this );
ASSERT( (&_tcsi.m_cell) == this );
ASSERT_VALID( (&wndListBox) );
ASSERT_VALID( (&_tcsi.m_wndGrid) );
_tcsi.m_nItemNoSelEndOK = wndListBox.GetCurSel();
_tcsi.m_bHelperSelChanged = true;
if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
{
LONG nItemCount = wndListBox.GetCount();
if( nItemCount > 0L )
{
LONG nCurSel = wndListBox.GetCurSel();
if( 0L <= nCurSel && nCurSel < nItemCount )
{
CString strSelLbText;
wndListBox.GetText( nCurSel, strSelLbText );
DWORD dwStyleEx = GetStyleEx();
bool bSendSelEndOkOnEqualText = ( ( dwStyleEx & __EGCS_EX_DO_NOT_NOTIFY_LB_SEL_FOR_EQUAL_TEXT ) != 0 ) ? true : false;
if( ! bSendSelEndOkOnEqualText )
{
CExtSafeString strCurrentText;
TextGet( strCurrentText );
if( strCurrentText == LPCTSTR(strSelLbText) )
return false;
}
bool bData = ( wndListBox.GetItemData( nCurSel ) != 0 ) ? true : false;
DataSet( bData );
_tcsi.m_wndGrid.OnGridCellInputComplete( *this, _tcsi.m_nColNo, _tcsi.m_nRowNo, _tcsi.m_nColType, _tcsi.m_nRowType, wndListBox.GetSafeHwnd() );
} // if( 0L <= nCurSel && nCurSel < nItemCount )
} // if( nItemCount > 0L )
} // if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
return false;
}
bool CExtGridCellUpDownFontWeight::OnPopupListBoxSelEndOK(
CExtPopupInplaceListBox & wndListBox,
CExtGridCell::TrackCellStateInfo_t & _tcsi
)
{
ASSERT_VALID( this );
ASSERT( (&_tcsi.m_cell) == this );
ASSERT_VALID( (&wndListBox) );
ASSERT_VALID( (&_tcsi.m_wndGrid) );
_tcsi.m_nItemNoSelEndOK = wndListBox.GetCurSel();
_tcsi.m_bHelperSelChanged = true;
if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
{
LONG nItemCount = wndListBox.GetCount();
if( nItemCount > 0L )
{
LONG nCurSel = wndListBox.GetCurSel();
if( 0L <= nCurSel && nCurSel < nItemCount )
{
CString strSelLbText;
wndListBox.GetText( nCurSel, strSelLbText );
DWORD dwStyleEx = GetStyleEx();
bool bSendSelEndOkOnEqualText = ( ( dwStyleEx & __EGCS_EX_DO_NOT_NOTIFY_LB_SEL_FOR_EQUAL_TEXT ) != 0 ) ? true : false;
if( ! bSendSelEndOkOnEqualText )
{
CExtSafeString strCurrentText;
TextGet( strCurrentText );
if( strCurrentText == LPCTSTR(strSelLbText) )
return false;
}
DWORD dwFontWeight = (DWORD) wndListBox.GetItemData( nCurSel );
CString strText;
strText.Format( _T("%d"), int(dwFontWeight) );
TextSet( LPCTSTR(strText) );
_tcsi.m_wndGrid.OnGridCellInputComplete( *this, _tcsi.m_nColNo, _tcsi.m_nRowNo, _tcsi.m_nColType, _tcsi.m_nRowType, wndListBox.GetSafeHwnd() );
} // if( 0L <= nCurSel && nCurSel < nItemCount )
} // if( nItemCount > 0L )
} // if( (wndListBox.GetStyle()&LBS_HASSTRINGS) != 0 )
return false;
}