基本信息
源码名称:datagridview 自定义单元格样式以及内容
源码大小:0.09M
文件格式:.rar
开发语言:C#
更新时间:2017-02-28
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 3 元 
   源码介绍


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;
using System.Collections;

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

        private void Form1_Load(object sender, EventArgs e)
        {
            DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
            m_CAtDataGridView.Columns.Insert(0, newColumn);
            newColumn.HeaderText = "选择";            
            DataGridViewTextBoxColumn Texture = new DataGridViewTextBoxColumn();
            Texture.HeaderText = "字段";
            m_CAtDataGridView.Columns.Insert(1, Texture);
            //
            DataGridViewComboBoxColumn dcob = new DataGridViewComboBoxColumn();
            m_CAtDataGridView.Columns.Insert(2, dcob);
            dcob.HeaderText = "纹理路径";            
            dcob.Items.AddRange(new string[] { "Test1", "Test2", "Test3", "Test4" });

            //foreach (string field in table_Field)
            for (int i = 0; i < 5;i   )
            {
                DataGridViewRow newrow = new DataGridViewRow();
                newrow.CreateCells(m_CAtDataGridView);
                newrow.Cells[2].Value = "Test2";// 设置默认值
                newrow.Cells[0].Value = true;
                newrow.Cells[1].Value = "t"   i.ToString();
                m_CAtDataGridView.Rows.Add(newrow);
            }            
            dcob.Selected = true;
            // 不显示新添加行
            m_CAtDataGridView.AllowUserToAddRows = false;
            m_CAtDataGridView.AutoSize = false;
            //m_CAtDataGridView.RowHeadersVisible = false;
            // 行颜色变化
            m_CAtDataGridView.RowsDefaultCellStyle.BackColor = Color.FromArgb(255, 90, 0);
            m_CAtDataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(50, 205, 50);
            m_CAtDataGridView.GridColor = Color.FromArgb(16, 139, 87);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Hashtable HashFieldTex = new Hashtable();
            int iNum = m_CAtDataGridView.Rows.Count;

            try 
            {
                for (int i = 0; i < iNum; i  )
                {
                    string Chos = m_CAtDataGridView.Rows[i].Cells[1].Value.ToString();
                    string Textrue = m_CAtDataGridView.Rows[i].Cells[2].Value.ToString();
                    HashFieldTex.Add(Chos, Textrue);
                }
            }
            catch (Exception ex)
            {
                string mes = ex.Message;
            }
        }

        private void m_CAtDataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            using (SolidBrush b = new SolidBrush(m_CAtDataGridView.RowHeadersDefaultCellStyle.ForeColor))
                e.Graphics.DrawString((e.RowIndex   1).ToString(),
                    e.InheritedRowStyle.Font, b, e.RowBounds.Location.X, e.RowBounds.Location.Y); 
        }
    }
}