Commit 297dd00a HZH

add treeGrid

1 个父辈 94da23c3
......@@ -54,5 +54,9 @@ namespace HZH_Controls.Controls
/// </summary>
/// <param name="blnSelected">是否选中</param>
void SetSelect(bool blnSelected);
/// <summary>
/// 行高
/// </summary>
int RowHeight { get; set; }
}
}
......@@ -30,6 +30,7 @@
{
this.panHead = new System.Windows.Forms.Panel();
this.panColumns = new System.Windows.Forms.TableLayoutPanel();
this.panHeadLeft = new System.Windows.Forms.Panel();
this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
this.panRow = new System.Windows.Forms.Panel();
this.panPage = new System.Windows.Forms.Panel();
......@@ -39,6 +40,7 @@
// panHead
//
this.panHead.Controls.Add(this.panColumns);
this.panHead.Controls.Add(this.panHeadLeft);
this.panHead.Controls.Add(this.ucSplitLine_H1);
this.panHead.Dock = System.Windows.Forms.DockStyle.Top;
this.panHead.Location = new System.Drawing.Point(0, 0);
......@@ -59,6 +61,14 @@
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;
//
// ucSplitLine_H1
//
this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
......@@ -77,6 +87,7 @@
this.panRow.Name = "panRow";
this.panRow.Size = new System.Drawing.Size(1061, 481);
this.panRow.TabIndex = 1;
this.panRow.SizeChanged += new System.EventHandler(this.panRow_SizeChanged);
//
// panPage
//
......@@ -109,6 +120,7 @@
private UCSplitLine_H ucSplitLine_H1;
private System.Windows.Forms.Panel panRow;
private System.Windows.Forms.Panel panPage;
private System.Windows.Forms.Panel panHeadLeft;
}
}
......@@ -18,6 +18,19 @@ namespace HZH_Controls.Controls
public partial class UCDataGridView : UserControl
{
#region 属性
private int m_headPadingLeft = 0;
[Description("标题左侧间距"), Category("自定义")]
public int HeadPadingLeft
{
get { return m_headPadingLeft; }
set
{
m_headPadingLeft = value;
this.panHeadLeft.Width = m_headPadingLeft;
}
}
private Font m_headFont = new Font("微软雅黑", 12F);
/// <summary>
/// 标题字体
......@@ -120,7 +133,7 @@ namespace HZH_Controls.Controls
}
}
private List<DataGridViewColumnEntity> m_columns;
private List<DataGridViewColumnEntity> m_columns = null;
/// <summary>
/// 列
/// </summary>
......@@ -135,7 +148,7 @@ namespace HZH_Controls.Controls
}
}
private object m_dataSource;
private object m_dataSource = null;
/// <summary>
/// 数据源,支持列表或table,如果使用翻页控件,请使用翻页控件的DataSource
/// </summary>
......@@ -145,15 +158,16 @@ namespace HZH_Controls.Controls
get { return m_dataSource; }
set
{
if (value == null)
return;
if (!(m_dataSource is DataTable) && (!typeof(IList).IsAssignableFrom(value.GetType())))
if (value != null)
{
throw new Exception("数据源不是有效的数据类型,请使用Datatable或列表");
if (!(m_dataSource is DataTable) && (!typeof(IList).IsAssignableFrom(value.GetType())))
{
throw new Exception("数据源不是有效的数据类型,请使用Datatable或列表");
}
}
m_dataSource = value;
ReloadSource();
if (m_columns != null && m_columns.Count > 0)
ReloadSource();
}
}
......@@ -174,6 +188,9 @@ namespace HZH_Controls.Controls
if (!typeof(IDataGridViewRow).IsAssignableFrom(value) || !value.IsSubclassOf(typeof(Control)))
throw new Exception("行控件没有实现IDataGridViewRow接口");
m_rowType = value;
ResetShowCount();
if (m_columns != null && m_columns.Count > 0)
ReloadSource();
}
}
IDataGridViewRow m_selectRow = null;
......@@ -196,16 +213,46 @@ namespace HZH_Controls.Controls
{
get
{
if (m_isShowCheckBox)
return GetSelectRows();
}
}
private List<IDataGridViewRow> GetSelectRows()
{
List<IDataGridViewRow> lst = new List<IDataGridViewRow>();
if (m_isShowCheckBox)
{
lst.AddRange(Rows.FindAll(p => p.IsChecked));
}
else
{
lst.AddRange(new List<IDataGridViewRow>() { m_selectRow });
}
foreach (var row in Rows)
{
Control c = row as Control;
UCDataGridView grid = FindChildGrid(c);
lst.AddRange(grid.SelectRows);
}
return lst;
}
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)
{
return Rows.FindAll(p => p.IsChecked);
var grid = FindChildGrid(c);
if (grid != null)
return grid;
}
else
return new List<IDataGridViewRow>() { m_selectRow };
}
return null;
}
private UCPagerControlBase m_page = null;
/// <summary>
/// 翻页控件
......@@ -237,6 +284,17 @@ namespace HZH_Controls.Controls
}
}
private bool m_isAutoHeight = false;
/// <summary>
/// 自动适应最大高度(当为true时,需要手动计算高度,请慎用)
/// </summary>
[Browsable(false)]
public bool IsAutoHeight
{
get { return m_isAutoHeight; }
set { m_isAutoHeight = value; }
}
void page_ShowSourceChanged(object currentSource)
{
this.DataSource = currentSource;
......@@ -350,6 +408,8 @@ namespace HZH_Controls.Controls
{
if (DesignMode)
{ return; }
if (this.Height <= 0)
return;
ShowCount = this.panRow.Height / (m_rowHeight);
int intCha = this.panRow.Height % (m_rowHeight);
m_rowHeight += intCha / ShowCount;
......@@ -366,12 +426,14 @@ namespace HZH_Controls.Controls
{ return; }
try
{
if (m_columns == null || m_columns.Count <= 0)
return;
ControlHelper.FreezeControl(this.panRow, true);
this.panRow.Controls.Clear();
Rows = new List<IDataGridViewRow>();
if (m_columns == null || m_columns.Count <= 0)
return;
if (m_dataSource != null)
{
int intIndex = 0;
......@@ -389,8 +451,6 @@ namespace HZH_Controls.Controls
foreach (Control item in this.panRow.Controls)
{
if (intIndex >= intSourceCount)
{
item.Visible = false;
......@@ -408,7 +468,8 @@ namespace HZH_Controls.Controls
row.DataSource = (m_dataSource as IList)[intIndex];
}
row.BindingCellData();
item.Height = m_rowHeight;
if (row.RowHeight != m_rowHeight)
row.RowHeight = m_rowHeight;
item.Visible = true;
item.BringToFront();
if (lastItem == null)
......@@ -439,10 +500,10 @@ namespace HZH_Controls.Controls
Control rowControl = (row as Control);
rowControl.Height = m_rowHeight;
this.panRow.Controls.Add(rowControl);
row.RowHeight = m_rowHeight;
rowControl.Dock = DockStyle.Top;
row.CellClick += (a, b) => { SetSelectRow(rowControl, b); };
row.CellClick += (a, b) => { SetSelectRow((Control)a, b); };
row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(rowControl, b); };
row.SourceChanged += RowSourceChanged;
rowControl.BringToFront();
......@@ -464,6 +525,29 @@ namespace HZH_Controls.Controls
}
}
//void rowControl_SizeChanged(object sender, EventArgs e)
//{
// if (m_isAutoHeight)
// {
// int intHeightCount = 0;
// intHeightCount += (IsShowHead ? this.panHead.Height : 0) + (Page != null ? this.panPage.Height : 0);
// foreach (Control item in this.panRow.Controls)
// {
// intHeightCount += item.Height;
// }
// if (this.Parent.Name == "panChildGrid")
// {
// if (this.Parent.Height != intHeightCount)
// this.Parent.Height = intHeightCount;
// }
// else
// {
// if (this.Height != intHeightCount)
// this.Height = intHeightCount;
// }
// }
//}
/// <summary>
/// 快捷键
......@@ -565,29 +649,33 @@ namespace HZH_Controls.Controls
return;
this.FindForm().ActiveControl = this;
this.FindForm().ActiveControl = item;
if (m_selectRow != null)
{
if (m_selectRow == item)
return;
m_selectRow.SetSelect(false);
}
m_selectRow = item as IDataGridViewRow;
m_selectRow.SetSelect(true);
if (ItemClick != null)
{
ItemClick(item, e);
}
if (this.panRow.Controls.Count > 0)
if (m_selectRow != item)
{
if (item.Location.Y < 0)
if (m_selectRow != null)
{
this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.Controls[this.panRow.Controls.Count - 1].Location.Y) + item.Location.Y);
m_selectRow.SetSelect(false);
}
else if (item.Location.Y + m_rowHeight > this.panRow.Height)
m_selectRow = item as IDataGridViewRow;
m_selectRow.SetSelect(true);
if (this.panRow.Controls.Count > 0)
{
this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.AutoScrollPosition.Y) + item.Location.Y - this.panRow.Height + m_rowHeight);
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
{
......@@ -596,9 +684,23 @@ namespace HZH_Controls.Controls
}
private void UCDataGridView_Resize(object sender, EventArgs e)
{
if (this.Height <= 0)
return;
if (m_isAutoHeight)
return;
ResetShowCount();
ReloadSource();
}
#endregion
private void panRow_SizeChanged(object sender, EventArgs e)
{
//if (m_isAutoHeight)
//{
// int intHeightCount = (IsShowHead ? this.panHead.Height : 0) + (Page != null ? this.panPage.Height : 0) + panRow.Height;
// if (this.Height != intHeightCount)
// this.Height = intHeightCount;
//}
}
}
}
......@@ -59,7 +59,19 @@ namespace HZH_Controls.Controls
}
}
}
int m_rowHeight = 40;
public int RowHeight
{
get
{
return m_rowHeight;
}
set
{
m_rowHeight = value;
this.Height = value;
}
}
#endregion
......@@ -97,7 +109,7 @@ namespace HZH_Controls.Controls
{
if (CellClick != null)
{
CellClick(sender, new DataGridViewEventArgs()
CellClick(this, new DataGridViewEventArgs()
{
CellControl = this,
CellIndex = (sender as Control).Tag.ToInt()
......@@ -189,6 +201,5 @@ namespace HZH_Controls.Controls
}
}
}
}
namespace HZH_Controls.Controls
{
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.panChildGrid = new System.Windows.Forms.Panel();
this.panChildLeft = new System.Windows.Forms.Panel();
this.panMain = new System.Windows.Forms.Panel();
this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
this.ucDGVChild = new HZH_Controls.Controls.UCDataGridView();
this.ucSplitLine_V1 = new HZH_Controls.Controls.UCSplitLine_V();
this.panChildGrid.SuspendLayout();
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(637, 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);
//
// panChildGrid
//
this.panChildGrid.Controls.Add(this.ucDGVChild);
this.panChildGrid.Controls.Add(this.ucSplitLine_V1);
this.panChildGrid.Controls.Add(this.panChildLeft);
this.panChildGrid.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panChildGrid.Location = new System.Drawing.Point(0, 65);
this.panChildGrid.Name = "panChildGrid";
this.panChildGrid.Size = new System.Drawing.Size(661, 0);
this.panChildGrid.TabIndex = 0;
this.panChildGrid.SizeChanged += new System.EventHandler(this.panChildGrid_SizeChanged);
//
// panChildLeft
//
this.panChildLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.panChildLeft.Dock = System.Windows.Forms.DockStyle.Left;
this.panChildLeft.Location = new System.Drawing.Point(0, 0);
this.panChildLeft.Name = "panChildLeft";
this.panChildLeft.Size = new System.Drawing.Size(24, 0);
this.panChildLeft.TabIndex = 1;
this.panChildLeft.Tag = "0";
//
// 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(0, 0);
this.panMain.Name = "panMain";
this.panMain.Size = new System.Drawing.Size(661, 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(0, 64);
this.ucSplitLine_H1.Name = "ucSplitLine_H1";
this.ucSplitLine_H1.Size = new System.Drawing.Size(661, 1);
this.ucSplitLine_H1.TabIndex = 1;
this.ucSplitLine_H1.TabStop = false;
//
// ucDGVChild
//
this.ucDGVChild.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ucDGVChild.BackColor = System.Drawing.Color.White;
this.ucDGVChild.HeadFont = new System.Drawing.Font("微软雅黑", 12F);
this.ucDGVChild.HeadHeight = 40;
this.ucDGVChild.HeadPadingLeft = 0;
this.ucDGVChild.HeadTextColor = System.Drawing.Color.Black;
this.ucDGVChild.IsAutoHeight = false;
this.ucDGVChild.IsShowCheckBox = false;
this.ucDGVChild.IsShowHead = false;
this.ucDGVChild.Location = new System.Drawing.Point(25, 0);
this.ucDGVChild.Name = "ucDGVChild";
this.ucDGVChild.Page = null;
this.ucDGVChild.RowHeight = 40;
this.ucDGVChild.RowType = typeof(HZH_Controls.Controls.UCDataGridViewRow);
this.ucDGVChild.Size = new System.Drawing.Size(636, 100);
this.ucDGVChild.TabIndex = 0;
this.ucDGVChild.SizeChanged += new System.EventHandler(this.ucDGVChild_SizeChanged);
//
// 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(24, 0);
this.ucSplitLine_V1.Name = "ucSplitLine_V1";
this.ucSplitLine_V1.Size = new System.Drawing.Size(1, 0);
this.ucSplitLine_V1.TabIndex = 0;
this.ucSplitLine_V1.TabStop = 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.panChildGrid);
this.Name = "UCDataGridViewTreeRow";
this.Size = new System.Drawing.Size(661, 65);
this.panChildGrid.ResumeLayout(false);
this.panMain.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel panCells;
private UCSplitLine_H ucSplitLine_H1;
private System.Windows.Forms.Panel panLeft;
private System.Windows.Forms.Panel panChildGrid;
private UCDataGridView ucDGVChild;
private System.Windows.Forms.Panel panChildLeft;
private System.Windows.Forms.Panel panMain;
private UCSplitLine_V ucSplitLine_V1;
}
}
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;
namespace HZH_Controls.Controls
{
[ToolboxItem(false)]
public partial class UCDataGridViewTreeRow : UserControl, IDataGridViewRow
{
#region 属性
public event DataGridViewEventHandler CheckBoxChangeEvent;
public event DataGridViewEventHandler CellClick;
public event DataGridViewEventHandler SourceChanged;
public List<DataGridViewColumnEntity> Columns
{
get;
set;
}
public object DataSource
{
get;
set;
}
public bool IsShowCheckBox
{
get;
set;
}
private bool m_isChecked;
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;
}
}
}
int m_rowHeight = 40;
public int RowHeight
{
get
{
return m_rowHeight;
}
set
{
m_rowHeight = value;
this.Height = value;
}
}
#endregion
public UCDataGridViewTreeRow()
{
InitializeComponent();
this.ucDGVChild.RowType = this.GetType();
this.ucDGVChild.IsAutoHeight = true;
this.SizeChanged += UCDataGridViewTreeRow_SizeChanged;
this.ucDGVChild.ItemClick += (a, b) =>
{
if (CellClick != null)
{
CellClick(a, new DataGridViewEventArgs()
{
CellControl = (a as Control),
CellIndex = (a as Control).Tag.ToInt()
});
}
};
}
void UCDataGridViewTreeRow_SizeChanged(object sender, EventArgs e)
{
if (this.Parent.Parent.Parent != null && this.Parent.Parent.Parent.Name == "panChildGrid" && this.panLeft.Tag.ToInt() == 1)
{
int intHeight = this.Parent.Parent.Controls[0].Controls.ToArray().Sum(p => p.Height);
if (this.Parent.Parent.Parent.Height != intHeight)
this.Parent.Parent.Parent.Height = intHeight;
}
}
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();
}
}
}
}
panLeft.Tag = 0;
var proChildrens = DataSource.GetType().GetProperty("Childrens");
if (proChildrens != null)
{
var value = proChildrens.GetValue(DataSource, null);
if (value != 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;
}
if (intSourceCount > 0)
{
panLeft.BackgroundImage = Properties.Resources.caret_right;
panLeft.Enabled = true;
panChildGrid.Tag = value;
}
else
{
panLeft.BackgroundImage = null;
panLeft.Enabled = false;
panChildGrid.Tag = null;
}
}
else
{
panLeft.BackgroundImage = null;
panLeft.Enabled = false;
panChildGrid.Tag = null;
}
}
else
{
panLeft.BackgroundImage = null;
panLeft.Enabled = false;
panChildGrid.Tag = null;
}
}
void Item_MouseDown(object sender, MouseEventArgs e)
{
if (CellClick != null)
{
CellClick(this, new DataGridViewEventArgs()
{
CellControl = this,
CellIndex = (sender as Control).Tag.ToInt()
});
}
}
public void SetSelect(bool blnSelected)
{
if (blnSelected)
{
this.panMain.BackColor = Color.FromArgb(255, 247, 245);
}
else
{
this.panMain.BackColor = Color.Transparent;
}
}
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;
this.ucDGVChild.Rows.ForEach(p => p.IsChecked = box.Checked);
if (CheckBoxChangeEvent != null)
{
CheckBoxChangeEvent(a, new DataGridViewEventArgs()
{
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));
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 = ContentAlignment.MiddleCenter;
lbl.MouseDown += (a, b) =>
{
Item_MouseDown(a, b);
};
c = lbl;
}
this.panCells.Controls.Add(c, i, 0);
}
}
}
finally
{
ControlHelper.FreezeControl(this, false);
}
}
private void panChildGrid_SizeChanged(object sender, EventArgs e)
{
int intHeight = RowHeight + panChildGrid.Height;
if (panChildGrid.Height != 0)
this.ucDGVChild.Height = panChildGrid.Height;
if (this.Height != intHeight)
this.Height = intHeight;
}
private void panLeft_MouseDown(object sender, MouseEventArgs e)
{
try
{
ControlHelper.FreezeControl(this.FindForm(), true);
if (panLeft.Tag.ToInt() == 0)
{
var value = panChildGrid.Tag;
if (value != null)
{
panLeft.BackgroundImage = Properties.Resources.caret_down;
panLeft.Tag = 1;
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;
}
this.panChildGrid.Height = RowHeight * intSourceCount;
if (panChildGrid.Height > 0)
{
if (value != this.ucDGVChild.DataSource)
{
this.ucDGVChild.Columns = Columns;
this.ucDGVChild.RowHeight = RowHeight;
this.ucDGVChild.HeadPadingLeft = this.panLeft.Width;
this.ucDGVChild.IsShowCheckBox = IsShowCheckBox;
this.ucDGVChild.DataSource = value;
this.ucDGVChild.Rows.ForEach(p => p.IsChecked =this.IsChecked);
}
}
}
}
else
{
panLeft.Tag = 0;
panChildGrid.Height = 0;
panLeft.BackgroundImage = Properties.Resources.caret_right;
}
}
finally
{
ControlHelper.FreezeControl(this.FindForm(), false);
}
}
private void ucDGVChild_SizeChanged(object sender, EventArgs e)
{
}
}
}
<?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>
\ No newline at end of file
......@@ -65,6 +65,12 @@
<Compile Include="Controls\DataGridView\UCDataGridViewRow.Designer.cs">
<DependentUpon>UCDataGridViewRow.cs</DependentUpon>
</Compile>
<Compile Include="Controls\DataGridView\UCDataGridViewTreeRow.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\DataGridView\UCDataGridViewTreeRow.Designer.cs">
<DependentUpon>UCDataGridViewTreeRow.cs</DependentUpon>
</Compile>
<Compile Include="Controls\List\IListViewItem.cs" />
<Compile Include="Controls\List\IPageControl.cs" />
<Compile Include="Controls\List\PageControlEventHandler.cs" />
......@@ -420,6 +426,9 @@
<EmbeddedResource Include="Controls\DataGridView\UCDataGridViewRow.resx">
<DependentUpon>UCDataGridViewRow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\DataGridView\UCDataGridViewTreeRow.resx">
<DependentUpon>UCDataGridViewTreeRow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\DateTime\UCDatePickerExt.resx">
<DependentUpon>UCDatePickerExt.cs</DependentUpon>
</EmbeddedResource>
......@@ -671,6 +680,18 @@
<ItemGroup>
<None Include="Resources\sanjiao1.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\up.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\down.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\caret-down.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\caret-right.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>md "$(TargetDir)HandInput"
......
......@@ -83,6 +83,26 @@ namespace HZH_Controls.Properties {
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap caret_down {
get {
object obj = ResourceManager.GetObject("caret_down", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap caret_right {
get {
object obj = ResourceManager.GetObject("caret_right", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap checkbox0 {
get {
object obj = ResourceManager.GetObject("checkbox0", resourceCulture);
......
......@@ -229,4 +229,10 @@
<data name="sanjiao2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\sanjiao2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="caret_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\caret-down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="caret_right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\caret-right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
\ No newline at end of file
......@@ -34,11 +34,10 @@
// ucDataGridView1
//
this.ucDataGridView1.BackColor = System.Drawing.Color.White;
this.ucDataGridView1.Columns = null;
this.ucDataGridView1.DataSource = null;
this.ucDataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.ucDataGridView1.HeadFont = new System.Drawing.Font("微软雅黑", 12F);
this.ucDataGridView1.HeadHeight = 40;
this.ucDataGridView1.HeadPadingLeft = 24;
this.ucDataGridView1.HeadTextColor = System.Drawing.Color.Black;
this.ucDataGridView1.IsShowCheckBox = false;
this.ucDataGridView1.IsShowHead = true;
......
......@@ -19,6 +19,9 @@ namespace Test
private void FrmTemp1Test_Load(object sender, EventArgs e)
{
this.ucDataGridView1.RowType = typeof(UCDataGridViewTreeRow);
this.ucDataGridView1.IsAutoHeight = true;
List<DataGridViewColumnEntity> lstCulumns = new List<DataGridViewColumnEntity>();
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "ID", HeadText = "编号", Width = 70, WidthType = SizeType.Absolute });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Name", HeadText = "姓名", Width = 50, WidthType = SizeType.Percent });
......@@ -39,6 +42,7 @@ namespace Test
Sex = i % 2
};
lstSource.Add(model);
AddChilds(model, 5);
}
var page = new UCPagerControl2();
......@@ -46,6 +50,26 @@ namespace Test
this.ucDataGridView1.Page = page;
this.ucDataGridView1.First();
}
private void AddChilds(TestModel tm, int intCount)
{
if (intCount <= 0)
return;
tm.Childrens = new List<TestModel>();
for (int i = 0; i < 5; i++)
{
TestModel model = new TestModel()
{
ID = i.ToString(),
Age = 3 * i,
Name = intCount + "——" + i,
Birthday = DateTime.Now.AddYears(-10),
Sex = i % 2
};
tm.Childrens.Add(model);
AddChilds(model, intCount - 1);
}
}
}
public class TestModel
......@@ -55,5 +79,6 @@ namespace Test
public int Age { get; set; }
public DateTime Birthday { get; set; }
public int Sex { get; set; }
public List<TestModel> Childrens { get; set; }
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!