• include a image in devexpress datagrid


    • Add an ImageCollection to yout form and add some icons 16x16 to it.
    • Add a column to the Grid for the icons.
    • Set the column's fieldName to image (whatever you like).
    • Set the column's UnboundType to Object.
    • Add a repositoryItemPictureEdit to the column's columnEdit.

    All the above can be done in the designer. Then do the following

    privatevoid gridView1_CustomUnboundColumnData(object sender,DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e){if(e.Column== colImage1 && e.IsGetData){string someValueFromDatabase =(string)gridView1.GetRowCellValue(e.RowHandle, colOne);if(someValueFromDatabase =="a"){//Set an icon with index 0
                e.Value= imageCollection1.Images(0);}else{//Set an icon with index 1
                e.Value= imageCollection1.Images(1);}}}

    The key here is handling the CustomUnboundColumnData and the repositoryItemPictureEdit.

    ***

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using DevExpress.XtraEditors.Repository;
    
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            private DataTable CreateTable(int RowCount)
            {
                Image[] images = new Image[] { WindowsApplication1.Properties.Resources.about, WindowsApplication1.Properties.Resources.add, WindowsApplication1.Properties.Resources.apple, WindowsApplication1.Properties.Resources.arrow_down, WindowsApplication1.Properties.Resources.arrow_left};
                DataTable tbl = new DataTable();
                tbl.Columns.Add("Name", typeof(string));
                tbl.Columns.Add("ID", typeof(int));
                tbl.Columns.Add("Number", typeof(int));
                tbl.Columns.Add("Date", typeof(DateTime));
                tbl.Columns.Add("Image", typeof(Image));
                for (int i = 0; i < RowCount; i++)
                    tbl.Rows.Add(new object[] { String.Format("Name{0}", i), i, 3 - i, DateTime.Now.AddDays(i), images[i % images.Length] });
                return tbl;
            }
    
            public Form1()
            {
                InitializeComponent();
                gridControl1.DataSource = CreateTable(20);
                gridView1.Columns["Image"].ColumnEdit = new RepositoryItemPictureEdit();
            }
        }
    }
  • 相关阅读:
    关于Mac上的开发工具
    关于VS2008和VS2013中字体的选择
    实验四 使用ASP.NET内置对象 总结
    实验三 使用ASP.NET常用服务器控件 总结
    实验二 C#程序设计 总结
    实验一 ASP.NET应用环境配置 总结
    关于PHP.INI中的错误ERROR报告级别设置
    获取当前网址跟目录
    PHP获取站点根目录
    php 上传图片
  • 原文地址:https://www.cnblogs.com/zeroone/p/3536468.html
Copyright © 2020-2023  润新知