110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.ComponentModel;
using System.Windows.Forms;
public class DataGridViewCustomColumn_1 : DataGridViewColumn
{
private int m_decimalPlace;
/// <summary>
/// 小数位数
/// </summary>
[Description("小数位数"), Browsable(true), Category("财务显示单元格")]
public int DecimalPlace
{
get { return m_decimalPlace != 0 ? m_decimalPlace : 2; }
set
{
if (m_decimalPlace != value)
{
if (value < 0)
throw new Exception("《小数位数》不可以小于 0 !");
else
{
this.m_decimalPlace = value;
}
}
}
}
public DataGridViewCustomColumn_1()
: base(new DataGridViewCustomCell_1())
{
}
}
public class DataGridViewCustomCell_1 : DataGridViewTextBoxCell
{
}
using System;
using System.ComponentModel;
using System.Windows.Forms;
public class DataGridViewCustomColumn_2 : DataGridViewColumn
{
private int m_decimalPlace;
/// <summary>
/// 小数位数
/// </summary>
[Description("小数位数"), Browsable(true), Category("财务显示单元格")]
public int DecimalPlace
{
get { return m_decimalPlace != 0 ? m_decimalPlace : 2; }
set
{
if (m_decimalPlace != value)
{
if (value < 0)
throw new Exception("《小数位数》不可以小于 0 !");
else
{
this.m_decimalPlace = value;
DataGridViewCustomCell_2 customCell = (DataGridViewCustomCell_2)this.CellTemplate;
customCell.DecimalPlace = value;
}
}
}
}
public DataGridViewCustomColumn_2()
: base(new DataGridViewCustomCell_2())
{
}
}
public class DataGridViewCustomCell_2 : DataGridViewTextBoxCell
{
private int m_decimalPlace;
/// <summary>
/// 小数位数
/// </summary>
public int DecimalPlace
{
get { return m_decimalPlace; }
set
{
if (m_decimalPlace != value)
{
if (value < 0)
throw new Exception("《小数位数》不可以小于 0 !");
else
m_decimalPlace = value;
}
}
}
}
using System;
using System.ComponentModel;
using System.Windows.Forms;
public class DataGridViewCustomColumn_3 : DataGridViewColumn
{
private int m_decimalPlace;
/// <summary>
/// 小数位数
/// </summary>
[Description("小数位数"), Browsable(true), Category("财务显示单元格")]
public int DecimalPlace
{
get { return m_decimalPlace != 0 ? m_decimalPlace : 2; }
set
{
if (m_decimalPlace != value)
{
if (value < 0)
throw new Exception("《小数位数》不可以小于 0 !");
else
{
this.m_decimalPlace = value;
DataGridViewCustomCell_3 customCell = (DataGridViewCustomCell_3)this.CellTemplate;
customCell.DecimalPlace = value;
if (this.DataGridView != null && this.DataGridView.Rows != null)
{
int rowCount = this.DataGridView.Rows.Count;
for (int x = 0; x < rowCount; x++)
{
foreach (DataGridViewCell dgvCell in this.DataGridView.Rows.SharedRow(x).Cells)
{
if (dgvCell is DataGridViewCustomCell_3)
(dgvCell as DataGridViewCustomCell_3).DecimalPlace = value;
}
}
}
}
}
}
}
public DataGridViewCustomColumn_3()
: base(new DataGridViewCustomCell_3())
{
}
}
public class DataGridViewCustomCell_3 : DataGridViewTextBoxCell
{
private int m_decimalPlace;
/// <summary>
/// 小数位数
/// </summary>
public int DecimalPlace
{
get
{
DataGridViewCustomColumn_3 customColumn = OwningColumn as DataGridViewCustomColumn_3;
if (customColumn != null)
{
if (customColumn.DecimalPlace != 0)
{
return customColumn.DecimalPlace;
}
}
return m_decimalPlace;
}
set
{
if (m_decimalPlace != value)
{
if (value < 0)
throw new Exception("《小数位数》不可以小于 0 !");
else
m_decimalPlace = value;
}
}
}
}
using System;
using System.ComponentModel;
using System.Windows.Forms;
public class DataGridViewCustomColumn_1 : DataGridViewColumn
{
public override object Clone()
{
DataGridViewCustomColumn_1 col = (DataGridViewCustomColumn_1)base.Clone();
col.DecimalPlace = this.DecimalPlace;
return col;
}
private int m_decimalPlace;
/// <summary>
/// 小数位数
/// </summary>
[Description("小数位数"), Browsable(true), Category("财务显示单元格")]
public int DecimalPlace
{
get
{
return m_decimalPlace != 0 ? m_decimalPlace : 2;
}
set
{
if (m_decimalPlace != value)
{
if (value < 0)
throw new Exception("《小数位数》不可以小于 0 !");
else
{
this.m_decimalPlace = value;
}
}
}
}
public DataGridViewCustomColumn_1()
: base(new DataGridViewCustomCell_1())
{
}
}
public class DataGridViewCustomCell_1 : DataGridViewTextBoxCell
{
}
namespace WindowsApplication37
{
partial class test
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.CustomColumn1 = new DataGridViewCustomColumn_1();
this.CustomColumn2 = new DataGridViewCustomColumn_2();
this.CustomColumn3 = new DataGridViewCustomColumn_3();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.CustomColumn1,
this.CustomColumn2,
this.CustomColumn3});
this.dataGridView1.Location = new System.Drawing.Point(68, 26);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(598, 329);
this.dataGridView1.TabIndex = 0;
//
// CustomColumn1
//
this.CustomColumn1.DecimalPlace = 2;
this.CustomColumn1.HeaderText = "CustomColumn1";
this.CustomColumn1.Name = "CustomColumn1";
//
// CustomColumn2
//
this.CustomColumn2.DecimalPlace = 2;
this.CustomColumn2.HeaderText = "CustomColumn2";
this.CustomColumn2.Name = "CustomColumn2";
//
// CustomColumn3
//
this.CustomColumn3.DecimalPlace = 2;
this.CustomColumn3.HeaderText = "CustomColumn3";
this.CustomColumn3.Name = "CustomColumn3";
//
// test
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(754, 380);
this.Controls.Add(this.dataGridView1);
this.Name = "test";
this.Text = "test";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private DataGridViewCustomColumn_1 CustomColumn1;
private DataGridViewCustomColumn_2 CustomColumn2;
private DataGridViewCustomColumn_3 CustomColumn3;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication37
{
public partial class test : Form
{
public test()
{
InitializeComponent();
}
}
}
namespace WindowsApplication37
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column1 = new WindowsApplication37.FinanceTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewComboBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.dataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column3,
this.Column1,
this.Column2});
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle2;
this.dataGridView1.Location = new System.Drawing.Point(58, 62);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(566, 336);
this.dataGridView1.TabIndex = 0;
//
// Column3
//
this.Column3.HeaderText = "Column3";
this.Column3.Name = "Column3";
//
// Column1
//
this.Column1.DecimalPlace = 2;
this.Column1.HeaderText = "Column1";
this.Column1.LineBold = 0F;
this.Column1.Name = "Column1";
this.Column1.NormalColor = System.Drawing.Color.Gray;
this.Column1.RedColor = System.Drawing.Color.Red;
this.Column1.SpecialColor = System.Drawing.Color.Blue;
//
// Column2
//
this.Column2.HeaderText = "Column2";
this.Column2.Name = "Column2";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(664, 504);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private FinanceTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewComboBoxColumn Column2;
}
}