VS2003 下GridControl的列显示成图片+文字的形式实现
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(12, 12); 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 = 22; repositoryItemImageComboBoxStatus.Items.AddRange(new ImageComboBoxItem[] { new ImageComboBoxItem("",CustAllocStatus.PRE_SOLICIT,0), new ImageComboBoxItem("",CustAllocStatus.SOLICITING,1), new ImageComboBoxItem("",CustAllocStatus.PRE_SOLICIT_TALK,2), new ImageComboBoxItem("",CustAllocStatus.PRE_PROMOTE,3), new ImageComboBoxItem("",CustAllocStatus.PRE_MANAGER_TALK,4), new ImageComboBoxItem("",CustAllocStatus.DEALED,5), new ImageComboBoxItem("",CustAllocStatus.DEFEATED,6), }); } else { repositoryItemImageComboBoxStatus.Items.AddRange(new ImageComboBoxItem[] { new ImageComboBoxItem("待招揽",CustAllocStatus.PRE_SOLICIT,0), new ImageComboBoxItem("招揽中",CustAllocStatus.SOLICITING,1), new ImageComboBoxItem("待招揽复谈",CustAllocStatus.PRE_SOLICIT_TALK,2), new ImageComboBoxItem("待现场促进",CustAllocStatus.PRE_PROMOTE,3), new ImageComboBoxItem("待经理复谈",CustAllocStatus.PRE_MANAGER_TALK,4), new ImageComboBoxItem("已成交",CustAllocStatus.DEALED,5), new ImageComboBoxItem("已战败",CustAllocStatus.DEFEATED,6), }); } 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中读取