这种表格怎么实现?

tcziflw2010 2013-09-23 06:17:17

...全文
157 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
flashposition 2013-09-23
  • 打赏
  • 举报
回复
自绘DataGridView
threenewbee 2013-09-23
  • 打赏
  • 举报
回复
引用 3 楼 tcziflw2010 的回复:
[quote=引用 2 楼 caozhy 的回复:] DataGridView装入图片(图片可以现画)
用DevExpress控件的话,有哪些可以[/quote] 思路类似。只要支持图片列。
threenewbee 2013-09-23
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.AllowUserToAddRows = false;
            var c1 = new DataGridViewTextBoxColumn();
            c1.HeaderText = "属性";
            var c2 = new DataGridViewImageColumn();
            c2.HeaderText = "颜色";
            dataGridView1.Columns.Add(c1);
            dataGridView1.Columns.Add(c2);
            var row1 = new DataGridViewRow();
            row1.Cells.Add(new DataGridViewTextBoxCell());
            row1.Cells.Add(new DataGridViewImageCell());
            row1.Cells[0].Value = "Red";
            row1.Cells[1].Value = CreateImage(Color.Red);
            dataGridView1.Rows.Add(row1);
            var row2 = new DataGridViewRow();
            row2.Cells.Add(new DataGridViewTextBoxCell());
            row2.Cells.Add(new DataGridViewImageCell());
            row2.Cells[0].Value = "Blue";
            row2.Cells[1].Value = CreateImage(Color.Blue);
            dataGridView1.Rows.Add(row2);
        }

        private Image CreateImage(Color color)
        {
            Bitmap bmp = new Bitmap(100, 20);
            var g = Graphics.FromImage(bmp);
            g.FillRectangle(new SolidBrush(color), 0, 0, bmp.Width, bmp.Height);
            return bmp;
        }
    }
}
在窗体上放一个DataGridView,双击窗体,在Form_Load中添加上述代码。 运行
tcziflw2010 2013-09-23
  • 打赏
  • 举报
回复
引用 2 楼 caozhy 的回复:
DataGridView装入图片(图片可以现画)
用DevExpress控件的话,有哪些可以
threenewbee 2013-09-23
  • 打赏
  • 举报
回复
DataGridView装入图片(图片可以现画)
tcziflw2010 2013-09-23
  • 打赏
  • 举报
回复
主要是颜色一列

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧