DataGridView結合ImageList實現映像列

來源:互聯網
上載者:User
實作類別似AutoCAD或者PhotoShop中圖層的效果。層名稱,層狀態,鎖定,顯示。
總結一下DataGridView的小技巧:1.代碼添加列,次序是由右至左,即越先添加的列,越靠右。2.代碼添加行,先添加行數,再往行裡加資料。   dataGridView1.Rows.Add(3);   dataGridView1.Rows[0].Cells[0].Value = "圖層一";3.圖片列的使用DataGridViewImageColumn4.去掉列名   dataGridView1.RowHeadersVisible = false;5.ListView也可以實現同樣的效果,但是介面很不好控制。   ListBox可以編輯但是無法添加映像列。   C# WinForm控制項ListBox點選可編輯(附源碼)

代碼: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 WinDataGridView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void BindData()
        {
            //去掉列名
            dataGridView1.RowHeadersVisible = false;
            //圖片列,列的添加是由右至左
            //是否鎖定
            DataGridViewImageColumn colLock = new DataGridViewImageColumn();
            colLock.Name = "layerLock";
            colLock.HeaderText = "鎖";
            colLock.Width = 20;
            dataGridView1.Columns.Insert(0, colLock);
            //是否顯示
            DataGridViewImageColumn colShow = new DataGridViewImageColumn();
            colShow.Name = "layerShow";
            colShow.HeaderText = "顯";
            colShow.Width = 20;
            dataGridView1.Columns.Insert(0, colShow);
            //編輯框列
            DataGridViewTextBoxColumn colTxt = new DataGridViewTextBoxColumn();
            colTxt.Name = "layerName";
            colTxt.HeaderText = "圖層名稱";
            dataGridView1.Columns.Insert(0, colTxt);
            //添加行資料
            dataGridView1.Rows.Add(3);
            this.dataGridView1.Rows[0].Cells[0].Value = "圖層一";
            this.dataGridView1.Rows[0].Cells[1].Value = imageList1.Images[0];
            this.dataGridView1.Rows[0].Cells[2].Value = imageList1.Images[2];
            this.dataGridView1.Rows[1].Cells[0].Value = "圖層二";
            this.dataGridView1.Rows[1].Cells[1].Value = imageList1.Images[0];
            this.dataGridView1.Rows[1].Cells[2].Value = imageList1.Images[3];
            this.dataGridView1.Rows[2].Cells[0].Value = "圖層三";
            this.dataGridView1.Rows[2].Cells[1].Value = imageList1.Images[1];
            this.dataGridView1.Rows[2].Cells[2].Value = imageList1.Images[2];
            this.dataGridView1.Rows[3].Cells[0].Value = "圖層四";
            this.dataGridView1.Rows[3].Cells[1].Value = imageList1.Images[1];
            this.dataGridView1.Rows[3].Cells[2].Value = imageList1.Images[3];
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            BindData();
        }
    }
}源碼:http://files.cnblogs.com/greatverve/WinDataGridView.rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.