找传奇、传世资源到传世资源站!

datagridview 自定义单元格样式以及内容

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

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); } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复