VS2003 下GridControl的列显示成图片+文字的形式实现

时间:2024-01-04 22:32:26
        public RC_CustomerSolicitListUC()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 //ADD BY TWH 2013-09-23,状态列显示为图片+文字的形式
SetStatusWithPic(gridView1, gridColumnStatus, false); } private void SetStatusWithPic(GridView aGridView1, GridColumn aColStatus, bool aOnlyImage)
{
ImageList imageList = new ImageList();
imageList.ImageSize = new Size(, );
imageList.ColorDepth = ColorDepth.Depth32Bit;
imageList.Images.Add(GetImage("待招揽.png"));
imageList.Images.Add(GetImage("招揽中.png"));
imageList.Images.Add(GetImage("待招揽复谈.png"));
imageList.Images.Add(GetImage("待现场促进.png"));
imageList.Images.Add(GetImage("待经理复谈.png"));
imageList.Images.Add(GetImage("已成交.png"));
imageList.Images.Add(GetImage("已战败.png")); imageList.TransparentColor = Color.Transparent; RepositoryItemImageComboBox repositoryItemImageComboBoxStatus = new RepositoryItemImageComboBox();
// aColStatus.ToolTip = "状态";
if (aOnlyImage)
{
aColStatus.Width = ; repositoryItemImageComboBoxStatus.Items.AddRange(new ImageComboBoxItem[]
{
new ImageComboBoxItem("",CustAllocStatus.PRE_SOLICIT,),
new ImageComboBoxItem("",CustAllocStatus.SOLICITING,),
new ImageComboBoxItem("",CustAllocStatus.PRE_SOLICIT_TALK,),
new ImageComboBoxItem("",CustAllocStatus.PRE_PROMOTE,),
new ImageComboBoxItem("",CustAllocStatus.PRE_MANAGER_TALK,),
new ImageComboBoxItem("",CustAllocStatus.DEALED,),
new ImageComboBoxItem("",CustAllocStatus.DEFEATED,),
});
}
else
{
repositoryItemImageComboBoxStatus.Items.AddRange(new ImageComboBoxItem[]
{
new ImageComboBoxItem("待招揽",CustAllocStatus.PRE_SOLICIT,),
new ImageComboBoxItem("招揽中",CustAllocStatus.SOLICITING,),
new ImageComboBoxItem("待招揽复谈",CustAllocStatus.PRE_SOLICIT_TALK,),
new ImageComboBoxItem("待现场促进",CustAllocStatus.PRE_PROMOTE,),
new ImageComboBoxItem("待经理复谈",CustAllocStatus.PRE_MANAGER_TALK,),
new ImageComboBoxItem("已成交",CustAllocStatus.DEALED,),
new ImageComboBoxItem("已战败",CustAllocStatus.DEFEATED,),
});
}
repositoryItemImageComboBoxStatus.Name = "repositoryItemImageComboBoxStatus";
repositoryItemImageComboBoxStatus.SmallImages = imageList;
//
aColStatus.ColumnEdit = repositoryItemImageComboBoxStatus;
} private Image GetImage(string aFileName)
{
// 从当前类型所在程序集里面提取“嵌入的资源文件”
return new Bitmap(this.GetType(), aFileName);
}

特别注意:增加的图片一定要与UC控件在同一文件夹下否则GetImage方法会无法读取到图片资源,当然在VS2005后VS都自带有Resources资源类,就不用像VS2003那样有较大的限制了。可以直接从Resources中读取