返回首页

{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( ); 

就是这样。有它的乐趣。

回答

评论会员:rodnarox 时间:2011/12/14
嗨,
认罪我这一解决方案感到非常高兴。但我有一个排序的行的一个问题。
是否有任何简单的方法,如何在ComboBox中的排序行吗?
当我真正的排序属性选项,那么这个意见被忽略。
感谢您的答案。
评论会员:rodnarox 时间:2011/12/14
我适用于简单的排序例程

1。定义我*. h文件:

typedef结构STRUCT_DEVICE_MAIN_TABLE
{
TCHAR dev_a [max_devices_count] [max_device_length]
TCHAR dev_b [max_devices_count] [max_device_length]
TCHAR dev_c [max_devices_count] [max_device_length]
TCHAR dev_d [max_devices_count] [max_device_length]
DEVICE_LIST_MAIN_TABLE;
2。 *. cpp文件中添加气泡交换功能:

/ /排序TCHARS的数组
BubbleSort无效(TCHAR名称[] [max_device_length],int的大小)
{
INT K = 0;
布尔做= FALSE;
INT限制= 0;
TCHAR名称[max_device_length] = _T ("");
(完成)
{做= TRUE;(INT Ñ = 0; NLT;大小- 1限制; GT;

/ /你的for循环操作"N""K"
(_tcscmp(名称[N],名[N - 1])GT; 0)
{
/ /你想通过名称的数组,而不是名称
交换(姓名,N,1);
交换(devlistMain.dev_b,N,N - 1);
交换(devlistMain.dev_c,N,N - 1);
交换(devlistMain.dev_d,N,N - 1); = FALSE;}
限制;
}
}

无效交换(TCHAR名称[] [max_device_length],INT N,K)
{
TCHAR温度[max_device_length]
  ; _tcscpy_s(温度,max_device_length,名称[N])
_tcscpy_s(名称[N],max_device_length,名称[K])
  ; _tcscpy_s(名称[K],max_device_length,温度);
}

3。呼叫泡沫功能

BubbleSort(devlistMain.dev_a,nCountOfDevices)
RodnaRox2008 {S2}
评论会员:rodnarox 时间:2011/12/14
对于这个完美的组合框升级{S3}
评论会员:jasper018 时间:2011/12/14
您好,

我在想,如果你能帮助?我想使用这个控制项,你用Windows C#应用程序中创建。我不确定如何访问或引用的控制。您的帮助,将不胜感激。期待你的答复。



J
评论会员:Gismow 时间:2011/12/14
您好,
我很抱歉,但实际的代码为C ** MFC控制实施的 - 我知道 - 而不是在C#中RESP可用。 。。NET

但我思考迁移到C#。

亲切的问候
gismow
评论会员:jasper018 时间:2011/12/14
嗯,让我知道如果你迁移到C#

感谢

J
评论会员:汉斯迪特里希 时间:2011/12/14
请包括释放模式下载的EXE。

最美好的祝愿,
汉斯


评论会员:Gismow 时间:2011/12/14
完成...

Thanx提示{S2}

关于
Gismow
评论会员:汉斯迪特里希 时间:2011/12/14


这看起来非常漂亮。作为一个未来的增强功能,请考虑添加工具提示,包含组合框行的所有列,最好是相同的格式。

最美好的祝愿,
汉斯

[