{A}{S0}简介
,这一切都始于为一个动态的多列组合框研究。我发现了在计数期间创造的控制行或固定的列数的限制。所以,我决定开发一个更灵活。
一切都开始与多列功能。后来,我看到了一个美妙的功能,在我在我的工作的发展与剑锋GridEX控制工作。它提供FormatConditions根据字段值来定义颜色和字体风格,让我实现了我对他们自己的变化。背景
有考虑到的一些特色:除了格式的条件,你可以定义一个默认的格式条件(类型FCO_Default),可以发现,如果没有匹配的格式条件。默认格式条件,于value1指针可以为NULL。列可以定义一个静态的宽度,或一个动态的宽度。 CalcDropdownListWidth()函数动态的宽度计算。因此,更改或添加行后,这个函数应该被调用。并非所有格式的条件经营使每一个类型的值(至使没有字符串的意义上说,包含数值没有感)的感觉,所以小心处理...使用代码在你的资源编辑器,创建一个ComboBox,并设置所有者绘制属性的变量,包括字符串属性设置为true,并为DropDownList下拉型。
使用ClassWizard来创建一个CComboBox对象在你的窗口。包括在你的类文件MCComboBox.h文件。CComboBox对象类型重命名CMCComboBox。在OnInitDialog()和OnInitialUpdate(),你必须定义列。可以添加在后面的代码格式的条件和行数据。
下面的代码片段,以产生意想不到的下拉列表,你可以看到在文章的顶部。该代码创建一个多列ComboBox的3列,3格式的条件下,一个默认格式的条件和30行数据:// Adding the columns
this->m_cboMultiColumn.Add_Column( );
this->m_cboMultiColumn.Add_Column( );
this->m_cboMultiColumn.Add_Column( );
// also use the format conditions in the edit control
this->m_cboMultiColumn.Set_ShowFormatConditionInEditField( true );
// add the format conditions
// red text and black background, if in column 0 the text "Row 3" appears
CFormatCondition *pFormatCondition =
this->m_cboMultiColumn.Create_FormatCondition( _T("TestCondition1"), 0,
CFormatCondition::FCO_Equal, new CMCCell( CString(_T("Row 3" ) ) ) );
if ( pFormatCondition != NULL )
{
pFormatCondition->Set_Bold( true );
pFormatCondition->Set_TextColor( RGB( 255, 0, 0 ) );
pFormatCondition->Set_BackColor( RGB( 0, 0, 0 ) );
}
// green text if in column 1 a date/time equal to 05.02.2007 12:00:00 appears
pFormatCondition = this->m_cboMultiColumn.Create_FormatCondition
( _T("Date 1"), 1, CFormatCondition::FCO_Equal,
new CMCCell( COleDateTime(2007, 2, 5, 12,0,0 ), CMCCell::CT_Time ) );
if ( pFormatCondition != NULL )
{
pFormatCondition->Set_TextColor( RGB( 0, 255, 0 ) );
}
// blue text if in column 1 a date/time greater than 05.02.2007 12:00:00 appears
pFormatCondition = this->m_cboMultiColumn.Create_FormatCondition
( _T("Date 2"), 2, CFormatCondition::FCO_GreaterThan, new CMCCell( (int)4 ) );
if ( pFormatCondition != NULL )
{
pFormatCondition->Set_TextColor( RGB( 0, 0, 255 ) );
}
// default format condition with golden text on dark red background,
// italic and striked out (uhhhhh.....)
pFormatCondition = this->m_cboMultiColumn.Create_FormatCondition
( _T("Default"), 2, CFormatCondition::FCO_Default, new CMCCell( (int)0 ) );
if ( pFormatCondition != NULL )
{
pFormatCondition->Set_TextColor( RGB( 255, 192, 64 ) );
pFormatCondition->Set_BackColor( RGB( 128, 0, 0 ) );
pFormatCondition->Set_Italic( true );
pFormatCondition->Set_StrikeThru( true );
}
// add 30 rows of data...
COleDateTime dtDateTime( 2007, 2,5,10,0,0);
for ( int nIndex = 0; nIndex < 30; nIndex++ )
{
CMCRow *pRow = new CMCRow( );
if ( pRow )
{
pRow->Set_ItemData( (long)( nIndex + 1 ) );
CString strText;
strText.Format( _T("Row %d"), nIndex, nIndex );
pRow->Set_CellValue( 0, strText );
pRow->Set_CellValue( 1, dtDateTime, CMCCell::CT_Time );
pRow->Set_CellValue( 2, nIndex );
this->m_cboMultiColumn.Add_Row( pRow );
}
dtDateTime += COleDateTimeSpan( 0, 1, 0, 0 );
}
// recalc the needed width for the dropdown list
this->m_cboMultiColumn.CalcDropdownListWidth( );
就是这样。有它的乐趣。