初始化提交
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="DataGridViewCellEntity.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class DataGridViewCellEntity.
|
||||
/// </summary>
|
||||
public class DataGridViewCellEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the title.
|
||||
/// </summary>
|
||||
/// <value>The title.</value>
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the width.
|
||||
/// </summary>
|
||||
/// <value>The width.</value>
|
||||
public int Width { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the width.
|
||||
/// </summary>
|
||||
/// <value>The type of the width.</value>
|
||||
public System.Windows.Forms.SizeType WidthType { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="DataGridViewCellEventArgs.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class DataGridViewEventArgs.
|
||||
/// Implements the <see cref="System.EventArgs" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.EventArgs" />
|
||||
public class DataGridViewEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the cell control.
|
||||
/// </summary>
|
||||
/// <value>The cell control.</value>
|
||||
public Control CellControl { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the index of the cell.
|
||||
/// </summary>
|
||||
/// <value>The index of the cell.</value>
|
||||
public int CellIndex { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the index of the row.
|
||||
/// </summary>
|
||||
/// <value>The index of the row.</value>
|
||||
public int RowIndex { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="DataGridViewCellEventHandler.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Delegate DataGridViewEventHandler
|
||||
/// </summary>
|
||||
/// <param name="sender">The sender.</param>
|
||||
/// <param name="e">The <see cref="DataGridViewEventArgs" /> instance containing the event data.</param>
|
||||
[Serializable]
|
||||
[ComVisible(true)]
|
||||
public delegate void DataGridViewEventHandler(object sender, DataGridViewEventArgs e);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate DataGridViewRowCustomEventHandler
|
||||
/// </summary>
|
||||
/// <param name="sender">The sender.</param>
|
||||
/// <param name="e">The <see cref="DataGridViewRowCustomEventArgs" /> instance containing the event data.</param>
|
||||
[Serializable]
|
||||
[ComVisible(true)]
|
||||
public delegate void DataGridViewRowCustomEventHandler(object sender, DataGridViewRowCustomEventArgs e);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="DataGridViewColumnEntity.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class DataGridViewColumnEntity.
|
||||
/// </summary>
|
||||
public class DataGridViewColumnEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the head text.
|
||||
/// </summary>
|
||||
/// <value>The head text.</value>
|
||||
public string HeadText { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the width.
|
||||
/// </summary>
|
||||
/// <value>The width.</value>
|
||||
public int Width { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the width.
|
||||
/// </summary>
|
||||
/// <value>The type of the width.</value>
|
||||
public System.Windows.Forms.SizeType WidthType { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the data field.
|
||||
/// </summary>
|
||||
/// <value>The data field.</value>
|
||||
public string DataField { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the format.
|
||||
/// </summary>
|
||||
/// <value>The format.</value>
|
||||
public Func<object, string> Format { get; set; }
|
||||
/// <summary>
|
||||
/// The text align
|
||||
/// </summary>
|
||||
private ContentAlignment _TextAlign = ContentAlignment.MiddleCenter;
|
||||
/// <summary>
|
||||
/// Gets or sets the text align.
|
||||
/// </summary>
|
||||
/// <value>The text align.</value>
|
||||
public ContentAlignment TextAlign { get { return _TextAlign; } set { _TextAlign = value; } }
|
||||
/// <summary>
|
||||
/// 自定义的单元格控件,一个实现IDataGridViewCustomCell的Control
|
||||
/// </summary>
|
||||
/// <value>The custom cell.</value>
|
||||
private Type customCellType = null;
|
||||
public Type CustomCellType
|
||||
{
|
||||
get
|
||||
{
|
||||
return customCellType;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!typeof(IDataGridViewCustomCell).IsAssignableFrom(value) || !value.IsSubclassOf(typeof(System.Windows.Forms.Control)))
|
||||
throw new Exception("行控件没有实现IDataGridViewCustomCell接口");
|
||||
customCellType = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-27-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="DataGridViewRowCustomEventArgs.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class DataGridViewRowCustomEventArgs.
|
||||
/// Implements the <see cref="System.EventArgs" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.EventArgs" />
|
||||
public class DataGridViewRowCustomEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the event.
|
||||
/// </summary>
|
||||
/// <value>The name of the event.</value>
|
||||
public string EventName { get; set; }
|
||||
|
||||
public object Data { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
public interface IDataGridViewCustomCell
|
||||
{
|
||||
/// <summary>
|
||||
/// 绑定行关联的数据
|
||||
/// </summary>
|
||||
/// <param name="obj">The object.</param>
|
||||
void SetBindSource(object obj);
|
||||
/// <summary>
|
||||
/// 自定义事件传递,用于单元格向行中传递此事件
|
||||
/// </summary>
|
||||
event DataGridViewRowCustomEventHandler RowCustomEvent;
|
||||
/// <summary>
|
||||
/// 关联数据源
|
||||
/// </summary>
|
||||
object DataSource { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="IDataGridViewRow.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface IDataGridViewRow
|
||||
/// </summary>
|
||||
public interface IDataGridViewRow
|
||||
{
|
||||
/// <summary>
|
||||
/// Occurs when [row custom event].
|
||||
/// </summary>
|
||||
event DataGridViewRowCustomEventHandler RowCustomEvent;
|
||||
/// <summary>
|
||||
/// CheckBox选中事件
|
||||
/// </summary>
|
||||
event DataGridViewEventHandler CheckBoxChangeEvent;
|
||||
/// <summary>
|
||||
/// 点击单元格事件
|
||||
/// </summary>
|
||||
event DataGridViewEventHandler CellClick;
|
||||
/// <summary>
|
||||
/// 数据源改变事件
|
||||
/// </summary>
|
||||
event DataGridViewEventHandler SourceChanged;
|
||||
/// <summary>
|
||||
/// 列参数,用于创建列数和宽度
|
||||
/// </summary>
|
||||
/// <value>The columns.</value>
|
||||
List<DataGridViewColumnEntity> Columns { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is show CheckBox.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is show CheckBox; otherwise, <c>false</c>.</value>
|
||||
bool IsShowCheckBox { get; set; }
|
||||
/// <summary>
|
||||
/// 是否选中
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is checked; otherwise, <c>false</c>.</value>
|
||||
bool IsChecked { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据源
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
object DataSource { get; set; }
|
||||
/// <summary>
|
||||
/// 添加单元格元素,仅做添加控件操作,不做数据绑定,数据绑定使用BindingCells
|
||||
/// </summary>
|
||||
void ReloadCells();
|
||||
/// <summary>
|
||||
/// 绑定数据到Cell
|
||||
/// </summary>
|
||||
/// <returns>返回true则表示已处理过,否则将进行默认绑定(通常只针对有Text值的控件)</returns>
|
||||
void BindingCellData();
|
||||
/// <summary>
|
||||
/// 设置选中状态,通常为设置颜色即可
|
||||
/// </summary>
|
||||
/// <param name="blnSelected">是否选中</param>
|
||||
void SetSelect(bool blnSelected);
|
||||
/// <summary>
|
||||
/// 行高
|
||||
/// </summary>
|
||||
/// <value>The height of the row.</value>
|
||||
int RowHeight { get; set; }
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
/// <value>The Index of the row.</value>
|
||||
int RowIndex { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCDataGridView.Designer.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCDataGridView.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
partial class UCDataGridView
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panHead = new System.Windows.Forms.Panel();
|
||||
this.panColumns = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.panHeadLeft = new System.Windows.Forms.Panel();
|
||||
this.panRow = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.ucSplitLine_H1 = new JinYuan.ControlLib.UCSplitLine_H();
|
||||
this.panHead.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panHead
|
||||
//
|
||||
this.panHead.Controls.Add(this.panColumns);
|
||||
this.panHead.Controls.Add(this.panHeadLeft);
|
||||
this.panHead.Controls.Add(this.ucSplitLine_H1);
|
||||
this.panHead.Location = new System.Drawing.Point(0, 0);
|
||||
this.panHead.Name = "panHead";
|
||||
this.panHead.Size = new System.Drawing.Size(1061, 40);
|
||||
this.panHead.TabIndex = 0;
|
||||
//
|
||||
// panColumns
|
||||
//
|
||||
this.panColumns.ColumnCount = 1;
|
||||
this.panColumns.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.panColumns.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panColumns.Location = new System.Drawing.Point(0, 0);
|
||||
this.panColumns.Name = "panColumns";
|
||||
this.panColumns.RowCount = 1;
|
||||
this.panColumns.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.panColumns.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
|
||||
this.panColumns.Size = new System.Drawing.Size(1061, 39);
|
||||
this.panColumns.TabIndex = 1;
|
||||
//
|
||||
// panHeadLeft
|
||||
//
|
||||
this.panHeadLeft.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.panHeadLeft.Location = new System.Drawing.Point(0, 0);
|
||||
this.panHeadLeft.Name = "panHeadLeft";
|
||||
this.panHeadLeft.Size = new System.Drawing.Size(0, 39);
|
||||
this.panHeadLeft.TabIndex = 2;
|
||||
//
|
||||
// panRow
|
||||
//
|
||||
this.panRow.AutoScroll = true;
|
||||
this.panRow.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panRow.Location = new System.Drawing.Point(0, 40);
|
||||
this.panRow.Name = "panRow";
|
||||
this.panRow.Size = new System.Drawing.Size(317, 225);
|
||||
this.panRow.TabIndex = 1;
|
||||
this.panRow.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panRow_Scroll);
|
||||
//
|
||||
// ucSplitLine_H1
|
||||
//
|
||||
this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
|
||||
this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.ucSplitLine_H1.Location = new System.Drawing.Point(0, 39);
|
||||
this.ucSplitLine_H1.Name = "ucSplitLine_H1";
|
||||
this.ucSplitLine_H1.Size = new System.Drawing.Size(1061, 1);
|
||||
this.ucSplitLine_H1.TabIndex = 0;
|
||||
this.ucSplitLine_H1.TabStop = false;
|
||||
//
|
||||
// UCDataGridView
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.Controls.Add(this.panRow);
|
||||
this.Controls.Add(this.panHead);
|
||||
this.Name = "UCDataGridView";
|
||||
this.Padding = new System.Windows.Forms.Padding(0, 40, 0, 0);
|
||||
this.Size = new System.Drawing.Size(317, 265);
|
||||
this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.UCDataGridView_Scroll);
|
||||
this.SizeChanged += new System.EventHandler(this.UCDataGridView_SizeChanged);
|
||||
this.panHead.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The pan head
|
||||
/// </summary>
|
||||
private System.Windows.Forms.Panel panHead;
|
||||
/// <summary>
|
||||
/// The pan columns
|
||||
/// </summary>
|
||||
private System.Windows.Forms.TableLayoutPanel panColumns;
|
||||
/// <summary>
|
||||
/// The uc split line h1
|
||||
/// </summary>
|
||||
private UCSplitLine_H ucSplitLine_H1;
|
||||
/// <summary>
|
||||
/// The pan head left
|
||||
/// </summary>
|
||||
private System.Windows.Forms.Panel panHeadLeft;
|
||||
private System.Windows.Forms.FlowLayoutPanel panRow;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,816 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCDataGridView.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections;
|
||||
using JinYuan.ControlLib.UCHelper;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCDataGridView.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public partial class UCDataGridView : UserControl
|
||||
{
|
||||
#region 属性
|
||||
/// <summary>
|
||||
/// The m head pading left
|
||||
/// </summary>
|
||||
private int m_headPadingLeft = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the head pading left.
|
||||
/// </summary>
|
||||
/// <value>The head pading left.</value>
|
||||
[Description("标题左侧间距"), Category("自定义")]
|
||||
public int HeadPadingLeft
|
||||
{
|
||||
get { return m_headPadingLeft; }
|
||||
set
|
||||
{
|
||||
m_headPadingLeft = value;
|
||||
this.panHeadLeft.Width = m_headPadingLeft;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m head font
|
||||
/// </summary>
|
||||
private Font m_headFont = new Font("微软雅黑", 12F);
|
||||
/// <summary>
|
||||
/// 标题字体
|
||||
/// </summary>
|
||||
/// <value>The head font.</value>
|
||||
[Description("标题字体"), Category("自定义")]
|
||||
public Font HeadFont
|
||||
{
|
||||
get { return m_headFont; }
|
||||
set { m_headFont = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The m head text color
|
||||
/// </summary>
|
||||
private Color m_headTextColor = Color.Black;
|
||||
/// <summary>
|
||||
/// 标题字体颜色
|
||||
/// </summary>
|
||||
/// <value>The color of the head text.</value>
|
||||
[Description("标题文字颜色"), Category("自定义")]
|
||||
public Color HeadTextColor
|
||||
{
|
||||
get { return m_headTextColor; }
|
||||
set { m_headTextColor = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m is show head
|
||||
/// </summary>
|
||||
private bool m_isShowHead = true;
|
||||
/// <summary>
|
||||
/// 是否显示标题
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is show head; otherwise, <c>false</c>.</value>
|
||||
[Description("是否显示标题"), Category("自定义")]
|
||||
public bool IsShowHead
|
||||
{
|
||||
get { return m_isShowHead; }
|
||||
set
|
||||
{
|
||||
if (m_isShowHead != value)
|
||||
{
|
||||
m_isShowHead = value;
|
||||
panHead.Visible = value;
|
||||
if (value)
|
||||
{
|
||||
this.panRow.Location = new Point(0, panHead.Height);
|
||||
this.panRow.Height = this.panRow.Height - panHead.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.panRow.Location = new Point(0, 0);
|
||||
this.panRow.Height = this.panRow.Height + panHead.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The m head height
|
||||
/// </summary>
|
||||
private int m_headHeight = 40;
|
||||
/// <summary>
|
||||
/// 标题高度
|
||||
/// </summary>
|
||||
/// <value>The height of the head.</value>
|
||||
[Description("标题高度"), Category("自定义")]
|
||||
public int HeadHeight
|
||||
{
|
||||
get { return m_headHeight; }
|
||||
set
|
||||
{
|
||||
m_headHeight = value;
|
||||
panHead.Height = value;
|
||||
this.Padding = new Padding(0, value, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m is show CheckBox
|
||||
/// </summary>
|
||||
private bool m_isShowCheckBox = false;
|
||||
/// <summary>
|
||||
/// 是否显示复选框
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is show CheckBox; otherwise, <c>false</c>.</value>
|
||||
[Description("是否显示选择框"), Category("自定义")]
|
||||
public bool IsShowCheckBox
|
||||
{
|
||||
get { return m_isShowCheckBox; }
|
||||
set
|
||||
{
|
||||
if (value != m_isShowCheckBox)
|
||||
{
|
||||
m_isShowCheckBox = value;
|
||||
LoadColumns();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m row height
|
||||
/// </summary>
|
||||
private int m_rowHeight = 40;
|
||||
/// <summary>
|
||||
/// 行高
|
||||
/// </summary>
|
||||
/// <value>The height of the row.</value>
|
||||
[Description("数据行高"), Category("自定义")]
|
||||
public int RowHeight
|
||||
{
|
||||
get { return m_rowHeight; }
|
||||
set { m_rowHeight = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the show count.
|
||||
/// </summary>
|
||||
/// <value>The show count.</value>
|
||||
[Description("当前高度可显示行个数"), Category("自定义")]
|
||||
public int ShowCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.panRow.Height / (m_rowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m columns
|
||||
/// </summary>
|
||||
private List<DataGridViewColumnEntity> m_columns = null;
|
||||
/// <summary>
|
||||
/// 列
|
||||
/// </summary>
|
||||
/// <value>The columns.</value>
|
||||
[Description("列"), Category("自定义")]
|
||||
public List<DataGridViewColumnEntity> Columns
|
||||
{
|
||||
get { return m_columns; }
|
||||
set
|
||||
{
|
||||
m_columns = value;
|
||||
LoadColumns();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m data source
|
||||
/// </summary>
|
||||
private object m_dataSource = null;
|
||||
/// <summary>
|
||||
/// 数据源,支持列表或table,如果使用翻页控件,请使用翻页控件的DataSource
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
/// <exception cref="Exception">数据源不是有效的数据类型,请使用Datatable或列表</exception>
|
||||
/// <exception cref="System.Exception">数据源不是有效的数据类型,请使用Datatable或列表</exception>
|
||||
[Description("数据源,支持列表或table,如果使用翻页控件,请使用翻页控件的DataSource"), Category("自定义")]
|
||||
public object DataSource
|
||||
{
|
||||
get { return m_dataSource; }
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (!(value is DataTable) && (!typeof(IList).IsAssignableFrom(value.GetType())))
|
||||
{
|
||||
throw new Exception("数据源不是有效的数据类型,请使用Datatable或列表");
|
||||
}
|
||||
}
|
||||
m_dataSource = value;
|
||||
if (m_columns != null && m_columns.Count > 0)
|
||||
{
|
||||
ReloadSource();
|
||||
}
|
||||
if (BindingSourceEvent != null)
|
||||
{
|
||||
BindingSourceEvent(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rows.
|
||||
/// </summary>
|
||||
/// <value>The rows.</value>
|
||||
public List<IDataGridViewRow> Rows { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The m row type
|
||||
/// </summary>
|
||||
private Type m_rowType = typeof(UCDataGridViewRow);
|
||||
/// <summary>
|
||||
/// 行元素类型,默认UCDataGridViewItem
|
||||
/// </summary>
|
||||
/// <value>The type of the row.</value>
|
||||
/// <exception cref="Exception">行控件没有实现IDataGridViewRow接口</exception>
|
||||
/// <exception cref="System.Exception">行控件没有实现IDataGridViewRow接口</exception>
|
||||
[Description("行控件类型,默认UCDataGridViewRow,如果不满足请自定义行控件实现接口IDataGridViewRow"), Category("自定义")]
|
||||
public Type RowType
|
||||
{
|
||||
get { return m_rowType; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
return;
|
||||
if (!typeof(IDataGridViewRow).IsAssignableFrom(value) || !value.IsSubclassOf(typeof(Control)))
|
||||
throw new Exception("行控件没有实现IDataGridViewRow接口");
|
||||
m_rowType = value;
|
||||
if (m_columns != null && m_columns.Count > 0)
|
||||
ReloadSource();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m select row
|
||||
/// </summary>
|
||||
IDataGridViewRow m_selectRow = null;
|
||||
/// <summary>
|
||||
/// 选中的节点
|
||||
/// </summary>
|
||||
/// <value>The select row.</value>
|
||||
[Description("选中行"), Category("自定义")]
|
||||
public IDataGridViewRow SelectRow
|
||||
{
|
||||
get { return m_selectRow; }
|
||||
private set { m_selectRow = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选中的行,如果显示CheckBox,则以CheckBox选中为准
|
||||
/// </summary>
|
||||
/// <value>The select rows.</value>
|
||||
[Description("选中的行,如果显示CheckBox,则以CheckBox选中为准"), Category("自定义")]
|
||||
public List<IDataGridViewRow> SelectRows
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetSelectRows();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the select rows.
|
||||
/// </summary>
|
||||
/// <returns>List<IDataGridViewRow>.</returns>
|
||||
private List<IDataGridViewRow> GetSelectRows()
|
||||
{
|
||||
List<IDataGridViewRow> lst = new List<IDataGridViewRow>();
|
||||
if (m_isShowCheckBox)
|
||||
{
|
||||
if (Rows != null && Rows.Count > 0)
|
||||
lst.AddRange(Rows.FindAll(p => p.IsChecked));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_selectRow != null)
|
||||
lst.AddRange(new List<IDataGridViewRow>() { m_selectRow });
|
||||
}
|
||||
if (Rows != null && Rows.Count > 0 && m_rowType == typeof(UCDataGridViewTreeRow))
|
||||
{
|
||||
foreach (UCDataGridViewTreeRow row in Rows)
|
||||
{
|
||||
lst.AddRange(FindTreeRowSelected(row));
|
||||
}
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
private List<IDataGridViewRow> FindTreeRowSelected(UCDataGridViewTreeRow row)
|
||||
{
|
||||
List<IDataGridViewRow> lst = new List<IDataGridViewRow>();
|
||||
var _lst = row.ChildrenRows.FindAll(p => p.IsChecked);
|
||||
lst.AddRange(_lst);
|
||||
foreach (UCDataGridViewTreeRow _row in row.ChildrenRows)
|
||||
{
|
||||
lst.AddRange(FindTreeRowSelected(_row));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the child grid.
|
||||
/// </summary>
|
||||
/// <param name="c">The c.</param>
|
||||
/// <returns>UCDataGridView.</returns>
|
||||
private UCDataGridView FindChildGrid(Control c)
|
||||
{
|
||||
foreach (Control item in c.Controls)
|
||||
{
|
||||
if (item is UCDataGridView)
|
||||
return item as UCDataGridView;
|
||||
else if (item.Controls.Count > 0)
|
||||
{
|
||||
var grid = FindChildGrid(item);
|
||||
if (grid != null)
|
||||
return grid;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
[Bindable(false)]
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override bool AutoScroll
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.AutoScroll;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.AutoScroll = value;
|
||||
}
|
||||
}
|
||||
#region 事件
|
||||
/// <summary>
|
||||
/// The head CheckBox change event
|
||||
/// </summary>
|
||||
[Description("选中标题选择框事件"), Category("自定义")]
|
||||
public EventHandler HeadCheckBoxChangeEvent;
|
||||
/// <summary>
|
||||
/// The head column click event
|
||||
/// </summary>
|
||||
[Description("标题点击事件"), Category("自定义")]
|
||||
public EventHandler HeadColumnClickEvent;
|
||||
/// <summary>
|
||||
/// Occurs when [item click].
|
||||
/// </summary>
|
||||
[Description("项点击事件"), Category("自定义")]
|
||||
public event DataGridViewEventHandler ItemClick;
|
||||
/// <summary>
|
||||
/// Occurs when [source changed].
|
||||
/// </summary>
|
||||
[Description("行数据源改变事件"), Category("自定义")]
|
||||
public event DataGridViewEventHandler RowSourceChangedEvent;
|
||||
/// <summary>
|
||||
/// Occurs when [row custom event].
|
||||
/// </summary>
|
||||
[Description("预留的自定义的事件,比如你需要在行上放置删改等按钮时,可以通过此事件传递出来"), Category("自定义")]
|
||||
public event DataGridViewRowCustomEventHandler RowCustomEvent;
|
||||
[Description("绑定数据源后事件"), Category("自定义")]
|
||||
public event EventHandler BindingSourceEvent;
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCDataGridView" /> class.
|
||||
/// </summary>
|
||||
public UCDataGridView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#region 私有方法
|
||||
#region 加载column
|
||||
/// <summary>
|
||||
/// 功能描述:加载column
|
||||
/// 作 者:HZH
|
||||
/// 创建日期:2019-08-08 17:51:50
|
||||
/// 任务编号:POS
|
||||
/// </summary>
|
||||
private void LoadColumns()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DesignMode)
|
||||
{ return; }
|
||||
|
||||
ControlHelper.FreezeControl(this.panHead, true);
|
||||
|
||||
this.panRow.Controls.Clear();
|
||||
this.panColumns.Controls.Clear();
|
||||
this.panColumns.ColumnStyles.Clear();
|
||||
|
||||
|
||||
if (m_columns != null && m_columns.Count() > 0)
|
||||
{
|
||||
int _width = 0;
|
||||
m_columns.ForEach(p =>
|
||||
{
|
||||
if (p.WidthType == SizeType.Absolute)
|
||||
{
|
||||
_width += p.Width;
|
||||
}
|
||||
else if (p.WidthType == SizeType.Percent)
|
||||
{
|
||||
_width += (int)((p.Width / 100f) * this.Width);
|
||||
}
|
||||
});
|
||||
if (m_isShowCheckBox)
|
||||
_width += 30;
|
||||
if (_width > this.Width)
|
||||
{
|
||||
//this.panRow.Width = _width;
|
||||
this.panHead.Width = _width;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_columns.Any(p => p.WidthType == SizeType.AutoSize))
|
||||
{
|
||||
//this.panRow.Width = this.Width;
|
||||
this.panHead.Width = this.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
//this.panRow.Width = _width;
|
||||
this.panHead.Width = _width;
|
||||
}
|
||||
}
|
||||
m_columns.FindAll(p => p.WidthType == SizeType.Absolute);
|
||||
m_columns.FindAll(p => p.WidthType == SizeType.Percent);
|
||||
int intColumnsCount = m_columns.Count();
|
||||
if (m_isShowCheckBox)
|
||||
{
|
||||
intColumnsCount++;
|
||||
}
|
||||
this.panColumns.ColumnCount = intColumnsCount;
|
||||
for (int i = 0; i < intColumnsCount; i++)
|
||||
{
|
||||
Control c = null;
|
||||
if (i == 0 && m_isShowCheckBox)
|
||||
{
|
||||
this.panColumns.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));
|
||||
|
||||
UCCheckBox box = new UCCheckBox();
|
||||
box.TextValue = "";
|
||||
box.Size = new Size(30, 30);
|
||||
box.CheckedChangeEvent += (a, b) =>
|
||||
{
|
||||
Rows.ForEach(p => p.IsChecked = box.Checked);
|
||||
if (HeadCheckBoxChangeEvent != null)
|
||||
{
|
||||
HeadCheckBoxChangeEvent(a, b);
|
||||
}
|
||||
};
|
||||
c = box;
|
||||
}
|
||||
else
|
||||
{
|
||||
var item = m_columns[i - (m_isShowCheckBox ? 1 : 0)];
|
||||
this.panColumns.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, item.Width));
|
||||
Label lbl = new Label();
|
||||
lbl.Name = "dgvColumns_" + i;
|
||||
lbl.Text = item.HeadText;
|
||||
lbl.Font = m_headFont;
|
||||
lbl.ForeColor = m_headTextColor;
|
||||
lbl.TextAlign = ContentAlignment.MiddleCenter;
|
||||
lbl.AutoSize = false;
|
||||
lbl.Dock = DockStyle.Fill;
|
||||
lbl.MouseDown += (a, b) =>
|
||||
{
|
||||
if (HeadColumnClickEvent != null)
|
||||
{
|
||||
HeadColumnClickEvent(a, b);
|
||||
}
|
||||
};
|
||||
c = lbl;
|
||||
}
|
||||
this.panColumns.Controls.Add(c, i, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ControlHelper.FreezeControl(this.panHead, false);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region 公共函数
|
||||
/// <summary>
|
||||
/// 刷新数据
|
||||
/// </summary>
|
||||
public void ReloadSource()
|
||||
{
|
||||
if (DesignMode)
|
||||
{ return; }
|
||||
try
|
||||
{
|
||||
ControlHelper.FreezeControl(this, true);
|
||||
panHead.Location = new Point(0, 0);
|
||||
Rows = new List<IDataGridViewRow>();
|
||||
if (m_columns == null || m_columns.Count <= 0)
|
||||
return;
|
||||
if (m_dataSource != null)
|
||||
{
|
||||
int intIndex = 0;
|
||||
|
||||
int intSourceCount = 0;
|
||||
if (m_dataSource is DataTable)
|
||||
{
|
||||
intSourceCount = (m_dataSource as DataTable).Rows.Count;
|
||||
}
|
||||
else if (typeof(IList).IsAssignableFrom(m_dataSource.GetType()))
|
||||
{
|
||||
intSourceCount = (m_dataSource as IList).Count;
|
||||
}
|
||||
|
||||
foreach (Control item in this.panRow.Controls)
|
||||
{
|
||||
if (intIndex >= intSourceCount)
|
||||
{
|
||||
item.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var row = (item as IDataGridViewRow);
|
||||
row.IsShowCheckBox = m_isShowCheckBox;
|
||||
if (m_dataSource is DataTable)
|
||||
{
|
||||
row.DataSource = (m_dataSource as DataTable).Rows[intIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
row.DataSource = (m_dataSource as IList)[intIndex];
|
||||
}
|
||||
row.BindingCellData();
|
||||
if (row.RowHeight != m_rowHeight)
|
||||
row.RowHeight = m_rowHeight;
|
||||
item.Visible = true;
|
||||
item.Width = panHead.Width;
|
||||
|
||||
Rows.Add(row);
|
||||
row.RowIndex = Rows.IndexOf(row);
|
||||
}
|
||||
intIndex++;
|
||||
}
|
||||
|
||||
if (intIndex < intSourceCount)
|
||||
{
|
||||
for (int i = intIndex; i < intSourceCount; i++)
|
||||
{
|
||||
IDataGridViewRow row = (IDataGridViewRow)Activator.CreateInstance(m_rowType);
|
||||
if (m_dataSource is DataTable)
|
||||
{
|
||||
row.DataSource = (m_dataSource as DataTable).Rows[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
row.DataSource = (m_dataSource as IList)[i];
|
||||
}
|
||||
row.Columns = m_columns;
|
||||
List<Control> lstCells = new List<Control>();
|
||||
row.IsShowCheckBox = m_isShowCheckBox;
|
||||
row.ReloadCells();
|
||||
row.BindingCellData();
|
||||
|
||||
Control rowControl = (row as Control);
|
||||
rowControl.Width = panHead.Width;
|
||||
row.RowHeight = m_rowHeight;
|
||||
row.CellClick += (a, b) => { this.FindForm().ActiveControl = this; rowControl.Focus(); SetSelectRow(rowControl, b); };
|
||||
row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(rowControl, b); };
|
||||
row.RowCustomEvent += (a, b) => { if (RowCustomEvent != null) { RowCustomEvent(a, b); } };
|
||||
row.SourceChanged += RowSourceChanged;
|
||||
Rows.Add(row);
|
||||
row.RowIndex = Rows.IndexOf(row);
|
||||
this.panRow.Controls.Add(rowControl);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//this.panRow.Height = intSourceCount * RowHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Control item in this.panRow.Controls)
|
||||
{
|
||||
item.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ControlHelper.FreezeControl(this, false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 快捷键
|
||||
/// </summary>
|
||||
/// <param name="msg">通过引用传递的 <see cref="T:System.Windows.Forms.Message" />,它表示要处理的窗口消息。</param>
|
||||
/// <param name="keyData"><see cref="T:System.Windows.Forms.Keys" /> 值之一,它表示要处理的键。</param>
|
||||
/// <returns>如果字符已由控件处理,则为 true;否则为 false。</returns>
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
{
|
||||
if (keyData == Keys.Up)
|
||||
{
|
||||
Previous();
|
||||
}
|
||||
else if (keyData == Keys.Down)
|
||||
{
|
||||
Next();
|
||||
}
|
||||
else if (keyData == Keys.Home)
|
||||
{
|
||||
First();
|
||||
}
|
||||
else if (keyData == Keys.End)
|
||||
{
|
||||
End();
|
||||
}
|
||||
return base.ProcessCmdKey(ref msg, keyData);
|
||||
}
|
||||
/// <summary>
|
||||
/// 选中第一个
|
||||
/// </summary>
|
||||
public void First()
|
||||
{
|
||||
if (Rows == null || Rows.Count <= 0)
|
||||
return;
|
||||
Control c = null;
|
||||
c = (Rows[0] as Control);
|
||||
SetSelectRow(c, new DataGridViewEventArgs() { RowIndex = 0 });
|
||||
}
|
||||
/// <summary>
|
||||
/// 选中上一个
|
||||
/// </summary>
|
||||
public void Previous()
|
||||
{
|
||||
if (Rows == null || Rows.Count <= 0)
|
||||
return;
|
||||
Control c = null;
|
||||
|
||||
int index = Rows.IndexOf(m_selectRow);
|
||||
if (index - 1 >= 0)
|
||||
{
|
||||
c = (Rows[index - 1] as Control);
|
||||
SetSelectRow(c, new DataGridViewEventArgs() { RowIndex = index - 1 });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 选中下一个
|
||||
/// </summary>
|
||||
public void Next()
|
||||
{
|
||||
if (Rows == null || Rows.Count <= 0)
|
||||
return;
|
||||
Control c = null;
|
||||
|
||||
int index = Rows.IndexOf(m_selectRow);
|
||||
if (index + 1 < Rows.Count)
|
||||
{
|
||||
c = (Rows[index + 1] as Control);
|
||||
SetSelectRow(c, new DataGridViewEventArgs() { RowIndex = index + 1 });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 选中最后一个
|
||||
/// </summary>
|
||||
public void End()
|
||||
{
|
||||
if (Rows == null || Rows.Count <= 0)
|
||||
return;
|
||||
Control c = null;
|
||||
c = (Rows[Rows.Count - 1] as Control);
|
||||
SetSelectRow(c, new DataGridViewEventArgs() { RowIndex = Rows.Count - 1 });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
/// <summary>
|
||||
/// Rows the source changed.
|
||||
/// </summary>
|
||||
/// <param name="sender">The sender.</param>
|
||||
/// <param name="e">The <see cref="DataGridViewEventArgs" /> instance containing the event data.</param>
|
||||
void RowSourceChanged(object sender, DataGridViewEventArgs e)
|
||||
{
|
||||
if (RowSourceChangedEvent != null)
|
||||
RowSourceChangedEvent(sender, e);
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the select row.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="e">The <see cref="DataGridViewEventArgs" /> instance containing the event data.</param>
|
||||
private void SetSelectRow(Control item, DataGridViewEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
ControlHelper.FreezeControl(this, true);
|
||||
if (item == null)
|
||||
return;
|
||||
if (item.Visible == false)
|
||||
return;
|
||||
this.FindForm().ActiveControl = this;
|
||||
this.FindForm().ActiveControl = item;
|
||||
if (m_selectRow != item)
|
||||
{
|
||||
if (m_selectRow != null)
|
||||
{
|
||||
m_selectRow.SetSelect(false);
|
||||
}
|
||||
m_selectRow = item as IDataGridViewRow;
|
||||
m_selectRow.SetSelect(true);
|
||||
|
||||
if (this.panRow.Controls.Count > 0)
|
||||
{
|
||||
if (item.Location.Y < 0)
|
||||
{
|
||||
this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.Controls[this.panRow.Controls.Count - 1].Location.Y) + item.Location.Y);
|
||||
}
|
||||
else if (item.Location.Y + m_rowHeight > this.panRow.Height)
|
||||
{
|
||||
this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.AutoScrollPosition.Y) + item.Location.Y - this.panRow.Height + m_rowHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ItemClick != null)
|
||||
{
|
||||
ItemClick(item, e);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ControlHelper.FreezeControl(this, false);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void UCDataGridView_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
//LoadColumns();
|
||||
//ReloadSource();
|
||||
}
|
||||
|
||||
private void UCDataGridView_Scroll(object sender, ScrollEventArgs e)
|
||||
{
|
||||
//if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
|
||||
//{
|
||||
// panHead.Location = new Point(0, this.VerticalScroll.Value + this.panRow.Location.Y - panHead.Height - 2);
|
||||
//}
|
||||
}
|
||||
|
||||
private void panRow_Scroll(object sender, ScrollEventArgs e)
|
||||
{
|
||||
if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll && this.panRow.Controls.Count > 0)
|
||||
{
|
||||
Console.WriteLine(this.panRow.HorizontalScroll.Value);
|
||||
Console.WriteLine(this.panRow.Controls[0].Location.X);
|
||||
panHead.Location = new Point(this.panRow.HorizontalScroll.Value * -1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,102 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCDataGridViewRow.Designer.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCDataGridViewRow.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
partial class UCDataGridViewRow
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.ucSplitLine_H1 = new JinYuan.ControlLib.UCSplitLine_H();
|
||||
this.panCells = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ucSplitLine_H1
|
||||
//
|
||||
this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
|
||||
this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.ucSplitLine_H1.Location = new System.Drawing.Point(0, 55);
|
||||
this.ucSplitLine_H1.Name = "ucSplitLine_H1";
|
||||
this.ucSplitLine_H1.Size = new System.Drawing.Size(661, 1);
|
||||
this.ucSplitLine_H1.TabIndex = 0;
|
||||
this.ucSplitLine_H1.TabStop = false;
|
||||
//
|
||||
// panCells
|
||||
//
|
||||
this.panCells.ColumnCount = 1;
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
|
||||
this.panCells.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panCells.Location = new System.Drawing.Point(0, 0);
|
||||
this.panCells.Name = "panCells";
|
||||
this.panCells.RowCount = 1;
|
||||
this.panCells.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.panCells.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
|
||||
this.panCells.Size = new System.Drawing.Size(661, 55);
|
||||
this.panCells.TabIndex = 1;
|
||||
//
|
||||
// UCDataGridViewItem
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.Controls.Add(this.panCells);
|
||||
this.Controls.Add(this.ucSplitLine_H1);
|
||||
this.Name = "UCDataGridViewItem";
|
||||
this.Size = new System.Drawing.Size(661, 56);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The uc split line h1
|
||||
/// </summary>
|
||||
private UCSplitLine_H ucSplitLine_H1;
|
||||
/// <summary>
|
||||
/// The pan cells
|
||||
/// </summary>
|
||||
private System.Windows.Forms.TableLayoutPanel panCells;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-09-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCDataGridViewRow.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using JinYuan.ControlLib.UCHelper;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCDataGridViewRow.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// Implements the <see cref="JinYuan.ControlLib.Controls.IDataGridViewRow" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
/// <seealso cref="JinYuan.ControlLib.Controls.IDataGridViewRow" />
|
||||
[ToolboxItem(false)]
|
||||
public partial class UCDataGridViewRow : UserControl, IDataGridViewRow
|
||||
{
|
||||
|
||||
#region 属性
|
||||
/// <summary>
|
||||
/// CheckBox选中事件
|
||||
/// </summary>
|
||||
public event DataGridViewEventHandler CheckBoxChangeEvent;
|
||||
/// <summary>
|
||||
/// Occurs when [row custom event].
|
||||
/// </summary>
|
||||
public event DataGridViewRowCustomEventHandler RowCustomEvent;
|
||||
/// <summary>
|
||||
/// 点击单元格事件
|
||||
/// </summary>
|
||||
public event DataGridViewEventHandler CellClick;
|
||||
|
||||
/// <summary>
|
||||
/// 数据源改变事件
|
||||
/// </summary>
|
||||
public event DataGridViewEventHandler SourceChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 列参数,用于创建列数和宽度
|
||||
/// </summary>
|
||||
/// <value>The columns.</value>
|
||||
public List<DataGridViewColumnEntity> Columns
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据源
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
public object DataSource
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
/// <value>The Index of the row.</value>
|
||||
public int RowIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is show CheckBox.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is show CheckBox; otherwise, <c>false</c>.</value>
|
||||
public bool IsShowCheckBox
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// The m is checked
|
||||
/// </summary>
|
||||
private bool m_isChecked;
|
||||
/// <summary>
|
||||
/// 是否选中
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is checked; otherwise, <c>false</c>.</value>
|
||||
public bool IsChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_isChecked;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (m_isChecked != value)
|
||||
{
|
||||
m_isChecked = value;
|
||||
(this.panCells.Controls.Find("check", false)[0] as UCCheckBox).Checked = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The m row height
|
||||
/// </summary>
|
||||
int m_rowHeight = 40;
|
||||
/// <summary>
|
||||
/// 行高
|
||||
/// </summary>
|
||||
/// <value>The height of the row.</value>
|
||||
public int RowHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_rowHeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_rowHeight = value;
|
||||
this.Height = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCDataGridViewRow" /> class.
|
||||
/// </summary>
|
||||
public UCDataGridViewRow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定数据到Cell
|
||||
/// </summary>
|
||||
/// <returns>返回true则表示已处理过,否则将进行默认绑定(通常只针对有Text值的控件)</returns>
|
||||
public void BindingCellData()
|
||||
{
|
||||
if (DataSource != null)
|
||||
{
|
||||
for (int i = 0; i < Columns.Count; i++)
|
||||
{
|
||||
DataGridViewColumnEntity com = Columns[i];
|
||||
var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false);
|
||||
if (cs != null && cs.Length > 0)
|
||||
{
|
||||
if (DataSource is DataRow)
|
||||
{
|
||||
DataRow row=DataSource as DataRow;
|
||||
if (com.Format != null)
|
||||
{
|
||||
cs[0].Text = com.Format(row[com.DataField]);
|
||||
}
|
||||
else
|
||||
{
|
||||
cs[0].Text = row[com.DataField].ToStringExt();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var pro = DataSource.GetType().GetProperty(com.DataField);
|
||||
|
||||
if (pro != null)
|
||||
{
|
||||
var value = pro.GetValue(DataSource, null);
|
||||
if (com.Format != null)
|
||||
{
|
||||
cs[0].Text = com.Format(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
cs[0].Text = value.ToStringExt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (Control item in this.panCells.Controls)
|
||||
{
|
||||
if (item is IDataGridViewCustomCell)
|
||||
{
|
||||
IDataGridViewCustomCell cell = item as IDataGridViewCustomCell;
|
||||
cell.RowCustomEvent += cell_RowCustomEvent;
|
||||
cell.SetBindSource(DataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cell_RowCustomEvent(object sender, DataGridViewRowCustomEventArgs e)
|
||||
{
|
||||
if (RowCustomEvent != null)
|
||||
{
|
||||
RowCustomEvent(sender, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the MouseDown event of the Item control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
|
||||
void Item_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (CellClick != null)
|
||||
{
|
||||
CellClick(this, new DataGridViewEventArgs()
|
||||
{
|
||||
CellControl = this,
|
||||
CellIndex = (sender as Control).Tag.ToInt(),
|
||||
RowIndex = this.RowIndex
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置选中状态,通常为设置颜色即可
|
||||
/// </summary>
|
||||
/// <param name="blnSelected">是否选中</param>
|
||||
public void SetSelect(bool blnSelected)
|
||||
{
|
||||
if (blnSelected)
|
||||
{
|
||||
this.BackColor = Color.FromArgb(255, 247, 245);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.BackColor = Color.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads the cells.
|
||||
/// </summary>
|
||||
public void ReloadCells()
|
||||
{
|
||||
try
|
||||
{
|
||||
ControlHelper.FreezeControl(this, true);
|
||||
this.panCells.Controls.Clear();
|
||||
this.panCells.ColumnStyles.Clear();
|
||||
|
||||
int intColumnsCount = Columns.Count();
|
||||
if (Columns != null && intColumnsCount > 0)
|
||||
{
|
||||
if (IsShowCheckBox)
|
||||
{
|
||||
intColumnsCount++;
|
||||
}
|
||||
this.panCells.ColumnCount = intColumnsCount;
|
||||
for (int i = 0; i < intColumnsCount; i++)
|
||||
{
|
||||
Control c = null;
|
||||
if (i == 0 && IsShowCheckBox)
|
||||
{
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));
|
||||
|
||||
UCCheckBox box = new UCCheckBox();
|
||||
box.Name = "check";
|
||||
box.TextValue = "";
|
||||
box.Size = new Size(30, 30);
|
||||
box.Dock = DockStyle.Fill;
|
||||
box.CheckedChangeEvent += (a, b) =>
|
||||
{
|
||||
IsChecked = box.Checked;
|
||||
if (CheckBoxChangeEvent != null)
|
||||
{
|
||||
CheckBoxChangeEvent(a, new DataGridViewEventArgs()
|
||||
{
|
||||
RowIndex = this.RowIndex,
|
||||
CellControl = box,
|
||||
CellIndex = 0
|
||||
});
|
||||
}
|
||||
};
|
||||
c = box;
|
||||
}
|
||||
else
|
||||
{
|
||||
var item = Columns[i - (IsShowCheckBox ? 1 : 0)];
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, item.Width));
|
||||
|
||||
if (item.CustomCellType == null)
|
||||
{
|
||||
Label lbl = new Label();
|
||||
lbl.Tag = i - (IsShowCheckBox ? 1 : 0);
|
||||
lbl.Name = "lbl_" + item.DataField;
|
||||
lbl.Font = new Font("微软雅黑", 12);
|
||||
lbl.ForeColor = Color.Black;
|
||||
lbl.AutoSize = false;
|
||||
lbl.Dock = DockStyle.Fill;
|
||||
lbl.TextAlign = item.TextAlign;
|
||||
lbl.MouseDown += (a, b) =>
|
||||
{
|
||||
Item_MouseDown(a, b);
|
||||
};
|
||||
c = lbl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Control cc = (Control)Activator.CreateInstance(item.CustomCellType);
|
||||
cc.Dock = DockStyle.Fill;
|
||||
c = cc;
|
||||
}
|
||||
}
|
||||
this.panCells.Controls.Add(c, i, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ControlHelper.FreezeControl(this, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,149 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-23-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCDataGridViewTreeRow.Designer.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCDataGridViewTreeRow.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
partial class UCDataGridViewTreeRow
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panCells = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.panLeft = new System.Windows.Forms.Panel();
|
||||
this.panMain = new System.Windows.Forms.Panel();
|
||||
this.ucSplitLine_H1 = new JinYuan.ControlLib.UCSplitLine_H();
|
||||
this.ucSplitLine_V1 = new JinYuan.ControlLib.UCSplitLine_V();
|
||||
this.panMain.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panCells
|
||||
//
|
||||
this.panCells.ColumnCount = 1;
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
|
||||
this.panCells.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panCells.Location = new System.Drawing.Point(24, 0);
|
||||
this.panCells.Name = "panCells";
|
||||
this.panCells.RowCount = 1;
|
||||
this.panCells.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.panCells.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 55F));
|
||||
this.panCells.Size = new System.Drawing.Size(636, 64);
|
||||
this.panCells.TabIndex = 2;
|
||||
//
|
||||
// panLeft
|
||||
//
|
||||
this.panLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
|
||||
this.panLeft.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.panLeft.Location = new System.Drawing.Point(0, 0);
|
||||
this.panLeft.Name = "panLeft";
|
||||
this.panLeft.Size = new System.Drawing.Size(24, 64);
|
||||
this.panLeft.TabIndex = 0;
|
||||
this.panLeft.Tag = "0";
|
||||
this.panLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panLeft_MouseDown);
|
||||
//
|
||||
// panMain
|
||||
//
|
||||
this.panMain.Controls.Add(this.panCells);
|
||||
this.panMain.Controls.Add(this.panLeft);
|
||||
this.panMain.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panMain.Location = new System.Drawing.Point(1, 0);
|
||||
this.panMain.Name = "panMain";
|
||||
this.panMain.Size = new System.Drawing.Size(660, 64);
|
||||
this.panMain.TabIndex = 0;
|
||||
//
|
||||
// ucSplitLine_H1
|
||||
//
|
||||
this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
|
||||
this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.ucSplitLine_H1.Location = new System.Drawing.Point(1, 64);
|
||||
this.ucSplitLine_H1.Name = "ucSplitLine_H1";
|
||||
this.ucSplitLine_H1.Size = new System.Drawing.Size(660, 1);
|
||||
this.ucSplitLine_H1.TabIndex = 1;
|
||||
this.ucSplitLine_H1.TabStop = false;
|
||||
//
|
||||
// ucSplitLine_V1
|
||||
//
|
||||
this.ucSplitLine_V1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
|
||||
this.ucSplitLine_V1.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.ucSplitLine_V1.Location = new System.Drawing.Point(0, 0);
|
||||
this.ucSplitLine_V1.Name = "ucSplitLine_V1";
|
||||
this.ucSplitLine_V1.Size = new System.Drawing.Size(1, 65);
|
||||
this.ucSplitLine_V1.TabIndex = 0;
|
||||
this.ucSplitLine_V1.TabStop = false;
|
||||
this.ucSplitLine_V1.Visible = false;
|
||||
//
|
||||
// UCDataGridViewTreeRow
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.Controls.Add(this.panMain);
|
||||
this.Controls.Add(this.ucSplitLine_H1);
|
||||
this.Controls.Add(this.ucSplitLine_V1);
|
||||
this.Name = "UCDataGridViewTreeRow";
|
||||
this.Size = new System.Drawing.Size(661, 65);
|
||||
this.panMain.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The pan cells
|
||||
/// </summary>
|
||||
private System.Windows.Forms.TableLayoutPanel panCells;
|
||||
/// <summary>
|
||||
/// The uc split line h1
|
||||
/// </summary>
|
||||
private UCSplitLine_H ucSplitLine_H1;
|
||||
/// <summary>
|
||||
/// The pan left
|
||||
/// </summary>
|
||||
private System.Windows.Forms.Panel panLeft;
|
||||
/// <summary>
|
||||
/// The pan main
|
||||
/// </summary>
|
||||
private System.Windows.Forms.Panel panMain;
|
||||
private UCSplitLine_V ucSplitLine_V1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : JinYuan.ControlLib
|
||||
// Created : 08-23-2019
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCDataGridViewTreeRow.cs">
|
||||
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
|
||||
// </copyright>
|
||||
//
|
||||
// Blog: https://www.cnblogs.com/bfyx
|
||||
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
|
||||
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
|
||||
//
|
||||
// If you use this code, please keep this note.
|
||||
// ***********************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections;
|
||||
using JinYuan.ControlLib.UCHelper;
|
||||
|
||||
namespace JinYuan.ControlLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCDataGridViewTreeRow.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// Implements the <see cref="JinYuan.ControlLib.Controls.IDataGridViewRow" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
/// <seealso cref="JinYuan.ControlLib.Controls.IDataGridViewRow" />
|
||||
[ToolboxItem(false)]
|
||||
public partial class UCDataGridViewTreeRow : UserControl, IDataGridViewRow
|
||||
{
|
||||
#region 属性
|
||||
/// <summary>
|
||||
/// CheckBox选中事件
|
||||
/// </summary>
|
||||
public event DataGridViewEventHandler CheckBoxChangeEvent;
|
||||
|
||||
/// <summary>
|
||||
/// 点击单元格事件
|
||||
/// </summary>
|
||||
public event DataGridViewEventHandler CellClick;
|
||||
|
||||
/// <summary>
|
||||
/// 数据源改变事件
|
||||
/// </summary>
|
||||
public event DataGridViewEventHandler SourceChanged;
|
||||
/// <summary>
|
||||
/// Occurs when [row custom event].
|
||||
/// </summary>
|
||||
public event DataGridViewRowCustomEventHandler RowCustomEvent;
|
||||
/// <summary>
|
||||
/// 列参数,用于创建列数和宽度
|
||||
/// </summary>
|
||||
/// <value>The columns.</value>
|
||||
public List<DataGridViewColumnEntity> Columns
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据源
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
public object DataSource
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
private int rowLevel = 0;
|
||||
/// <summary>
|
||||
/// 折叠的第几层,用于缩进
|
||||
/// </summary>
|
||||
public int RowLevel
|
||||
{
|
||||
get { return rowLevel; }
|
||||
set
|
||||
{
|
||||
rowLevel = value;
|
||||
this.Padding = new Padding(this.panLeft.Width / 2 * value, this.Padding.Top, this.panLeft.Right, this.Padding.Bottom);
|
||||
this.ucSplitLine_V1.Visible = value > 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 行号,树状图目前没有给予行号
|
||||
/// </summary>
|
||||
/// <value>The Index of the row.</value>
|
||||
public int RowIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is show CheckBox.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is show CheckBox; otherwise, <c>false</c>.</value>
|
||||
public bool IsShowCheckBox
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// The m is checked
|
||||
/// </summary>
|
||||
private bool m_isChecked;
|
||||
/// <summary>
|
||||
/// 是否选中
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is checked; otherwise, <c>false</c>.</value>
|
||||
public bool IsChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_isChecked;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (m_isChecked != value)
|
||||
{
|
||||
m_isChecked = value;
|
||||
(this.panCells.Controls.Find("check", false)[0] as UCCheckBox).Checked = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m row height
|
||||
/// </summary>
|
||||
int m_rowHeight = 40;
|
||||
/// <summary>
|
||||
/// 行高
|
||||
/// </summary>
|
||||
/// <value>The height of the row.</value>
|
||||
public int RowHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_rowHeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_rowHeight = value;
|
||||
this.Height = value;
|
||||
}
|
||||
}
|
||||
private List<UCDataGridViewTreeRow> childrenRows = new List<UCDataGridViewTreeRow>();
|
||||
|
||||
public List<UCDataGridViewTreeRow> ChildrenRows
|
||||
{
|
||||
get { return childrenRows; }
|
||||
set { childrenRows = value; }
|
||||
}
|
||||
private bool? isOpened = false;
|
||||
/// <summary>
|
||||
/// 是否打开状态
|
||||
/// </summary>
|
||||
public bool? IsOpened
|
||||
{
|
||||
get { return isOpened; }
|
||||
set
|
||||
{
|
||||
isOpened = value;
|
||||
if (value.HasValue)
|
||||
{
|
||||
panLeft.Enabled = true;
|
||||
if (value.Value)
|
||||
{
|
||||
panLeft.BackgroundImage = Properties.Resources.caret_down;
|
||||
}
|
||||
else
|
||||
{
|
||||
panLeft.BackgroundImage = Properties.Resources.caret_right;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
panLeft.BackgroundImage = null;
|
||||
panLeft.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCDataGridViewTreeRow" /> class.
|
||||
/// </summary>
|
||||
public UCDataGridViewTreeRow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定数据到Cell
|
||||
/// </summary>
|
||||
public void BindingCellData()
|
||||
{
|
||||
for (int i = 0; i < Columns.Count; i++)
|
||||
{
|
||||
DataGridViewColumnEntity com = Columns[i];
|
||||
var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false);
|
||||
if (cs != null && cs.Length > 0)
|
||||
{
|
||||
var pro = DataSource.GetType().GetProperty(com.DataField);
|
||||
if (pro != null)
|
||||
{
|
||||
var value = pro.GetValue(DataSource, null);
|
||||
if (com.Format != null)
|
||||
{
|
||||
cs[0].Text = com.Format(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
cs[0].Text = value.ToStringExt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (Control item in this.panCells.Controls)
|
||||
{
|
||||
if (item is IDataGridViewCustomCell)
|
||||
{
|
||||
IDataGridViewCustomCell cell = item as IDataGridViewCustomCell;
|
||||
cell.RowCustomEvent += cell_RowCustomEvent;
|
||||
cell.SetBindSource(DataSource);
|
||||
}
|
||||
}
|
||||
IsOpened = false;
|
||||
var proChildrens = DataSource.GetType().GetProperty("Childrens");
|
||||
if (proChildrens != null)
|
||||
{
|
||||
var value = proChildrens.GetValue(DataSource, null);
|
||||
if (value != null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
IsOpened = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IsOpened = null;
|
||||
}
|
||||
}
|
||||
|
||||
void cell_RowCustomEvent(object sender, DataGridViewRowCustomEventArgs e)
|
||||
{
|
||||
if (RowCustomEvent != null)
|
||||
RowCustomEvent(sender, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the MouseDown event of the Item control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
|
||||
void Item_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (CellClick != null)
|
||||
{
|
||||
CellClick(this, new DataGridViewEventArgs()
|
||||
{
|
||||
CellControl = this,
|
||||
CellIndex = (sender as Control).Tag.ToInt()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置选中状态,通常为设置颜色即可
|
||||
/// </summary>
|
||||
/// <param name="blnSelected">是否选中</param>
|
||||
public void SetSelect(bool blnSelected)
|
||||
{
|
||||
if (blnSelected)
|
||||
{
|
||||
this.panMain.BackColor = Color.FromArgb(255, 247, 245);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.panMain.BackColor = Color.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加单元格元素,仅做添加控件操作,不做数据绑定,数据绑定使用BindingCells
|
||||
/// </summary>
|
||||
public void ReloadCells()
|
||||
{
|
||||
try
|
||||
{
|
||||
ControlHelper.FreezeControl(this, true);
|
||||
this.panCells.Controls.Clear();
|
||||
this.panCells.ColumnStyles.Clear();
|
||||
|
||||
int intColumnsCount = Columns.Count();
|
||||
if (Columns != null && intColumnsCount > 0)
|
||||
{
|
||||
if (IsShowCheckBox)
|
||||
{
|
||||
intColumnsCount++;
|
||||
}
|
||||
this.panCells.ColumnCount = intColumnsCount;
|
||||
bool blnFirst = true;
|
||||
for (int i = 0; i < intColumnsCount; i++)
|
||||
{
|
||||
Control c = null;
|
||||
if (i == 0 && IsShowCheckBox)
|
||||
{
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));
|
||||
|
||||
UCCheckBox box = new UCCheckBox();
|
||||
box.Name = "check";
|
||||
box.TextValue = "";
|
||||
box.Size = new Size(30, 30);
|
||||
box.Dock = DockStyle.Fill;
|
||||
box.CheckedChangeEvent += box_CheckedChangeEvent;
|
||||
c = box;
|
||||
}
|
||||
else
|
||||
{
|
||||
var item = Columns[i - (IsShowCheckBox ? 1 : 0)];
|
||||
var w = item.Width - (blnFirst ? (this.panLeft.Width / 2 * rowLevel) : 0);
|
||||
if (w < 5)
|
||||
w = 5;
|
||||
this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, w));
|
||||
blnFirst = false;
|
||||
if (item.CustomCellType == null)
|
||||
{
|
||||
Label lbl = new Label();
|
||||
lbl.Tag = i - (IsShowCheckBox ? 1 : 0);
|
||||
lbl.Name = "lbl_" + item.DataField;
|
||||
lbl.Font = new Font("微软雅黑", 12);
|
||||
lbl.ForeColor = Color.Black;
|
||||
lbl.AutoSize = false;
|
||||
lbl.Dock = DockStyle.Fill;
|
||||
lbl.TextAlign = item.TextAlign;
|
||||
lbl.MouseDown += (a, b) =>
|
||||
{
|
||||
Item_MouseDown(a, b);
|
||||
};
|
||||
c = lbl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Control cc = (Control)Activator.CreateInstance(item.CustomCellType);
|
||||
cc.Dock = DockStyle.Fill;
|
||||
c = cc;
|
||||
}
|
||||
}
|
||||
this.panCells.Controls.Add(c, i, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ControlHelper.FreezeControl(this, false);
|
||||
}
|
||||
}
|
||||
|
||||
void box_CheckedChangeEvent(object sender, EventArgs e)
|
||||
{
|
||||
IsChecked = ((UCCheckBox)sender).Checked;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handles the MouseDown event of the panLeft control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
|
||||
private void panLeft_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsOpened.HasValue)
|
||||
return;
|
||||
ControlHelper.FreezeControl(this.FindForm(), true);
|
||||
if (!IsOpened.Value)
|
||||
{
|
||||
|
||||
IsOpened = !IsOpened;
|
||||
if (childrenRows.Count > 0)
|
||||
{
|
||||
childrenRows.ForEach(p =>
|
||||
{
|
||||
p.IsChecked = IsChecked;
|
||||
p.Visible = true;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var proChildrens = DataSource.GetType().GetProperty("Childrens");
|
||||
if (proChildrens != null)
|
||||
{
|
||||
var value = proChildrens.GetValue(DataSource, null);
|
||||
int intSourceCount = 0;
|
||||
if (value is DataTable)
|
||||
{
|
||||
intSourceCount = (value as DataTable).Rows.Count;
|
||||
}
|
||||
else if (typeof(IList).IsAssignableFrom(value.GetType()))
|
||||
{
|
||||
intSourceCount = (value as IList).Count;
|
||||
}
|
||||
for (int i = intSourceCount - 1; i >= 0; i--)
|
||||
{
|
||||
UCDataGridViewTreeRow row = new UCDataGridViewTreeRow();
|
||||
if (value is DataTable)
|
||||
{
|
||||
row.DataSource = (value as DataTable).Rows[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
row.DataSource = (value as IList)[i];
|
||||
}
|
||||
row.RowLevel = RowLevel + 1;
|
||||
row.Columns = Columns;
|
||||
row.IsShowCheckBox = IsShowCheckBox;
|
||||
row.ReloadCells();
|
||||
row.BindingCellData();
|
||||
|
||||
Control rowControl = (row as Control);
|
||||
row.RowHeight = m_rowHeight;
|
||||
rowControl.Width = this.Width;
|
||||
//rowControl.Dock = DockStyle.Top;
|
||||
row.CellClick += (a, b) => { CellClick(rowControl, b); };
|
||||
row.CheckBoxChangeEvent += (a, b) => { CheckBoxChangeEvent(rowControl, b); };
|
||||
row.RowCustomEvent += (a, b) => { if (RowCustomEvent != null) { RowCustomEvent(a, b); } };
|
||||
row.SourceChanged += SourceChanged;
|
||||
ChildrenRows.Add(row);
|
||||
row.RowIndex = ChildrenRows.IndexOf(row);
|
||||
|
||||
this.Parent.Controls.Add(rowControl);
|
||||
var index = this.Parent.Controls.GetChildIndex(this);
|
||||
this.Parent.Controls.SetChildIndex(row, index+1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HideChildrenRows(this);
|
||||
this.Height = m_rowHeight;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ControlHelper.FreezeControl(this.FindForm(), false);
|
||||
}
|
||||
}
|
||||
|
||||
private void HideChildrenRows(UCDataGridViewTreeRow row)
|
||||
{
|
||||
if (row.ChildrenRows.Count > 0)
|
||||
{
|
||||
foreach (var item in row.ChildrenRows)
|
||||
{
|
||||
HideChildrenRows(item);
|
||||
item.Hide();
|
||||
}
|
||||
row.IsOpened = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
Reference in New Issue
Block a user