Commit ba589629 HZH

datagridview绑定分页控件

1 个父辈 5f164a46
......@@ -335,47 +335,55 @@ namespace HZH_Controls.Controls
private void click_MouseDown(object sender, MouseEventArgs e)
{
if (this.Source != null && this.Source.Count > 0)
if (_frmAnchor == null || _frmAnchor.IsDisposed || _frmAnchor.Visible == false)
{
int intRow = 0;
int intCom = 1;
var p = this.PointToScreen(this.Location);
while (true)
if (this.Source != null && this.Source.Count > 0)
{
int intScreenHeight = Screen.PrimaryScreen.Bounds.Height;
if ((p.Y + this.Height + this.Source.Count / intCom * 50 < intScreenHeight || p.Y - this.Source.Count / intCom * 50 > 0)
&& (_dropPanelHeight <= 0 ? true : (this.Source.Count / intCom * 50 <= _dropPanelHeight)))
int intRow = 0;
int intCom = 1;
var p = this.PointToScreen(this.Location);
while (true)
{
intRow = this.Source.Count / intCom + (this.Source.Count % intCom != 0 ? 1 : 0);
break;
int intScreenHeight = Screen.PrimaryScreen.Bounds.Height;
if ((p.Y + this.Height + this.Source.Count / intCom * 50 < intScreenHeight || p.Y - this.Source.Count / intCom * 50 > 0)
&& (_dropPanelHeight <= 0 ? true : (this.Source.Count / intCom * 50 <= _dropPanelHeight)))
{
intRow = this.Source.Count / intCom + (this.Source.Count % intCom != 0 ? 1 : 0);
break;
}
intCom++;
}
intCom++;
}
UCTimePanel ucTime = new UCTimePanel();
ucTime.IsShowBorder = true;
int intWidth = this.Width / intCom;
if (intWidth < _ItemWidth)
intWidth = _ItemWidth;
Size size= new Size(intCom * intWidth, intRow * 50);
ucTime.Size =size;
ucTime.FirstEvent = true;
ucTime.SelectSourceEvent += ucTime_SelectSourceEvent;
ucTime.Row = intRow;
ucTime.Column = intCom;
List<KeyValuePair<string, string>> lst = new List<KeyValuePair<string, string>>();
foreach (var item in this.Source)
{
lst.Add(new KeyValuePair<string, string>(item.Key, item.Value));
}
ucTime.Source = lst;
UCTimePanel ucTime = new UCTimePanel();
ucTime.IsShowBorder = true;
int intWidth = this.Width / intCom;
if (intWidth < _ItemWidth)
intWidth = _ItemWidth;
Size size = new Size(intCom * intWidth, intRow * 50);
ucTime.Size = size;
ucTime.FirstEvent = true;
ucTime.SelectSourceEvent += ucTime_SelectSourceEvent;
ucTime.Row = intRow;
ucTime.Column = intCom;
List<KeyValuePair<string, string>> lst = new List<KeyValuePair<string, string>>();
foreach (var item in this.Source)
{
lst.Add(new KeyValuePair<string, string>(item.Key, item.Value));
}
ucTime.Source = lst;
ucTime.SetSelect(_selectedValue);
ucTime.SetSelect(_selectedValue);
_frmAnchor = new Forms.FrmAnchor(this, ucTime);
_frmAnchor.Load += (a, b) => { (a as Form).Size = size; };
_frmAnchor = new Forms.FrmAnchor(this, ucTime);
_frmAnchor.Load += (a, b) => { (a as Form).Size = size; };
_frmAnchor.Show(this.FindForm());
_frmAnchor.Show(this.FindForm());
}
}
else
{
_frmAnchor.Close();
}
}
......
......@@ -6,7 +6,7 @@ using System.Windows.Forms;
namespace HZH_Controls.Controls
{
public class DataGridViewCellEventArgs : EventArgs
public class DataGridViewEventArgs : EventArgs
{
public Control CellControl { get; set; }
public int CellIndex { get; set; }
......
......@@ -8,5 +8,5 @@ namespace HZH_Controls.Controls
{
[Serializable]
[ComVisible(true)]
public delegate void DataGridViewCellEventHandler(object sender, DataGridViewCellEventArgs e);
public delegate void DataGridViewEventHandler(object sender, DataGridViewEventArgs e);
}
......@@ -11,15 +11,15 @@ namespace HZH_Controls.Controls
/// <summary>
/// CheckBox选中事件
/// </summary>
event DataGridViewCellEventHandler CheckBoxChangeEvent;
event DataGridViewEventHandler CheckBoxChangeEvent;
/// <summary>
/// 点击单元格事件
/// </summary>
event DataGridViewCellEventHandler CellClick;
event DataGridViewEventHandler CellClick;
/// <summary>
/// 数据源改变事件
/// </summary>
event DataGridViewCellEventHandler SourceChanged;
event DataGridViewEventHandler SourceChanged;
/// <summary>
/// 列参数,用于创建列数和宽度
/// </summary>
......
......@@ -32,6 +32,7 @@
this.panColumns = new System.Windows.Forms.TableLayoutPanel();
this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
this.panRow = new System.Windows.Forms.Panel();
this.panPage = new System.Windows.Forms.Panel();
this.panHead.SuspendLayout();
this.SuspendLayout();
//
......@@ -74,14 +75,24 @@
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(1061, 525);
this.panRow.Size = new System.Drawing.Size(1061, 475);
this.panRow.TabIndex = 1;
//
// panPage
//
this.panPage.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panPage.Location = new System.Drawing.Point(0, 515);
this.panPage.Name = "panPage";
this.panPage.Size = new System.Drawing.Size(1061, 50);
this.panPage.TabIndex = 0;
this.panPage.Visible = false;
//
// UCDataGridView
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.panRow);
this.Controls.Add(this.panPage);
this.Controls.Add(this.panHead);
this.Name = "UCDataGridView";
this.Size = new System.Drawing.Size(1061, 565);
......@@ -97,6 +108,7 @@
private System.Windows.Forms.TableLayoutPanel panColumns;
private UCSplitLine_H ucSplitLine_H1;
private System.Windows.Forms.Panel panRow;
private System.Windows.Forms.Panel panPage;
}
}
......@@ -9,15 +9,16 @@ using System.Windows.Forms;
namespace HZH_Controls.Controls
{
[ToolboxItem(false)]
public partial class UCDataGridViewRow : UserControl, IDataGridViewRow
{
#region 属性
public event DataGridViewCellEventHandler CheckBoxChangeEvent;
public event DataGridViewEventHandler CheckBoxChangeEvent;
public event DataGridViewCellEventHandler CellClick;
public event DataGridViewEventHandler CellClick;
public event DataGridViewCellEventHandler SourceChanged;
public event DataGridViewEventHandler SourceChanged;
public List<DataGridViewColumnEntity> Columns
{
......@@ -81,7 +82,7 @@ namespace HZH_Controls.Controls
{
if (CellClick != null)
{
CellClick(sender, new DataGridViewCellEventArgs()
CellClick(sender, new DataGridViewEventArgs()
{
CellControl = this,
CellIndex = (sender as Control).Tag.ToInt()
......@@ -134,7 +135,7 @@ namespace HZH_Controls.Controls
IsChecked = box.Checked;
if (CheckBoxChangeEvent != null)
{
CheckBoxChangeEvent(a, new DataGridViewCellEventArgs()
CheckBoxChangeEvent(a, new DataGridViewEventArgs()
{
CellControl = box,
CellIndex = 0
......
......@@ -10,7 +10,7 @@ namespace HZH_Controls.Controls
/// <summary>
/// 数据源改变时发生
/// </summary>
event PageControlEventHandler ShowChanged;
event PageControlEventHandler ShowSourceChanged;
/// <summary>
/// 数据源
/// </summary>
......
namespace HZH_Controls.Controls.List
namespace HZH_Controls.Controls
{
partial class UCPagerControl
{
......@@ -64,7 +64,6 @@
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(68, 46);
this.panel4.TabIndex = 3;
this.panel4.Visible = false;
this.panel4.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel4_MouseDown);
//
// panel3
......@@ -75,7 +74,6 @@
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(68, 46);
this.panel3.TabIndex = 2;
this.panel3.Visible = false;
this.panel3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel3_MouseDown);
//
// panel2
......@@ -86,7 +84,6 @@
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(68, 46);
this.panel2.TabIndex = 1;
this.panel2.Visible = false;
this.panel2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel2_MouseDown);
//
// panel1
......@@ -97,7 +94,6 @@
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(68, 46);
this.panel1.TabIndex = 0;
this.panel1.Visible = false;
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
//
// UCPagerControl
......
......@@ -7,13 +7,14 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HZH_Controls.Controls.List
namespace HZH_Controls.Controls
{
[ToolboxItem(true)]
public partial class UCPagerControl : UCPagerControlBase
{
public UCPagerControl()
{
InitializeComponent();
InitializeComponent();
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
......
......@@ -9,6 +9,7 @@ using System.Windows.Forms;
namespace HZH_Controls.Controls
{
[ToolboxItem(false)]
public class UCPagerControlBase : UserControl, IPageControl
{
#region 构造
......@@ -39,9 +40,13 @@ namespace HZH_Controls.Controls
private void InitializeComponent()
{
this.SuspendLayout();
//
// UCPagerControlBase
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Name = "UCPagerControlBase";
this.Size = new System.Drawing.Size(304, 58);
this.Load += new System.EventHandler(this.UCPagerControlBase_Load);
this.ResumeLayout(false);
}
......@@ -52,13 +57,14 @@ namespace HZH_Controls.Controls
/// <summary>
/// 关联的数据源
/// </summary>
public List<object> DataSource { get; set; }
public event PageControlEventHandler ShowChanged;
public virtual List<object> DataSource { get; set; }
public event PageControlEventHandler ShowSourceChanged;
private int m_pageSize = 1;
/// <summary>
/// 每页显示数量
/// </summary>
public int PageSize
[Description("每页显示数量"), Category("自定义")]
public virtual int PageSize
{
get { return m_pageSize; }
set { m_pageSize = value; }
......@@ -67,7 +73,8 @@ namespace HZH_Controls.Controls
/// <summary>
/// 开始的下标
/// </summary>
public int StartIndex
[Description("开始的下标"), Category("自定义")]
public virtual int StartIndex
{
get { return startIndex; }
set
......@@ -83,18 +90,38 @@ namespace HZH_Controls.Controls
{
InitializeComponent();
}
public void FirstPage()
private void UCPagerControlBase_Load(object sender, EventArgs e)
{
if (DataSource == null)
ShowBtn(false, false);
else
{
ShowBtn(false, DataSource.Count > PageSize);
}
}
/// <summary>
/// 第一页
/// </summary>
public virtual void FirstPage()
{
if (DataSource == null)
return;
startIndex = 0;
var s = GetCurrentSource();
if (ShowChanged != null)
if (ShowSourceChanged != null)
{
ShowChanged(s);
ShowSourceChanged(s);
}
}
public void PreviousPage()
/// <summary>
/// 上一页
/// </summary>
public virtual void PreviousPage()
{
if (DataSource == null)
return;
if (startIndex == 0)
return;
startIndex -= m_pageSize;
......@@ -102,13 +129,18 @@ namespace HZH_Controls.Controls
startIndex = 0;
var s = GetCurrentSource();
if (ShowChanged != null)
if (ShowSourceChanged != null)
{
ShowChanged(s);
ShowSourceChanged(s);
}
}
public void NextPage()
/// <summary>
/// 下一页
/// </summary>
public virtual void NextPage()
{
if (DataSource == null)
return;
if (startIndex + m_pageSize >= DataSource.Count)
{
return;
......@@ -118,38 +150,47 @@ namespace HZH_Controls.Controls
startIndex = 0;
var s = GetCurrentSource();
if (ShowChanged != null)
if (ShowSourceChanged != null)
{
ShowChanged(s);
ShowSourceChanged(s);
}
}
public void EndPage()
/// <summary>
/// 最后一页
/// </summary>
public virtual void EndPage()
{
startIndex = DataSource.Count - 1 - m_pageSize;
if (DataSource == null)
return;
startIndex = DataSource.Count - m_pageSize;
if (startIndex < 0)
startIndex = 0;
var s = GetCurrentSource();
if (ShowChanged != null)
if (ShowSourceChanged != null)
{
ShowChanged(s);
ShowSourceChanged(s);
}
}
public void Reload()
/// <summary>
/// 刷新数据
/// </summary>
public virtual void Reload()
{
var s = GetCurrentSource();
if (ShowChanged != null)
if (ShowSourceChanged != null)
{
ShowChanged(s);
ShowSourceChanged(s);
}
}
public List<object> GetCurrentSource()
/// <summary>
/// 获取当前页数据
/// </summary>
/// <returns></returns>
public virtual List<object> GetCurrentSource()
{
if (DataSource == null)
return null;
int intShowCount = m_pageSize;
if (intShowCount + startIndex > DataSource.Count)
intShowCount = DataSource.Count - startIndex;
......@@ -185,9 +226,11 @@ namespace HZH_Controls.Controls
/// <summary>
/// 控制按钮显示
/// </summary>
/// <param name="blnLeftBtn"></param>
/// <param name="blnRightBtn"></param>
/// <param name="blnLeftBtn">是否显示上一页,第一页</param>
/// <param name="blnRightBtn">是否显示下一页,最后一页</param>
protected virtual void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{ }
}
}
......@@ -23,6 +23,7 @@ namespace HZH_Controls.Forms
/// </summary>
public partial class FrmAnchor : Form, IMessageFilter
{
Control m_parentControl = null;
private bool blnDown = true;
#region 构造函数
/// <summary>
......@@ -36,6 +37,7 @@ namespace HZH_Controls.Forms
/// <param name="deviation">偏移</param>
public FrmAnchor(Control parentControl, Control childControl, Point? deviation = null)
{
m_parentControl = parentControl;
InitializeComponent();
this.Size = childControl.Size;
this.HandleCreated += FrmDownBoard_HandleCreated;
......@@ -75,6 +77,7 @@ namespace HZH_Controls.Forms
public FrmAnchor(Control parentControl, Size size, Point? deviation = null)
{
m_parentControl = parentControl;
InitializeComponent();
this.Size = size;
this.HandleCreated += FrmDownBoard_HandleCreated;
......
......@@ -363,9 +363,9 @@ namespace HZH_Controls.Forms
public enum TipsState
{
Default = -1,
Success = -11426991,
Info = -13658444,
Warning = -486394,
Error = -4377041
Success = -6566849,
Info = -12477983,
Warning = -357816,
Error = -1097849
}
}
......@@ -412,6 +412,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram1.cd" />
<None Include="Resources\alarm.png" />
</ItemGroup>
<ItemGroup>
......
......@@ -57,13 +57,13 @@ namespace Test
}
this.ucListExt1.SetList(lst);
List<KeyValuePair<string, string>> lstHL = new List<KeyValuePair<string, string>>();
for (int i = 0; i < 30; i++)
{
lstHL.Add(new KeyValuePair<string, string>(i.ToString(), "选项" + i));
}
List<KeyValuePair<string, string>> lstHL = new List<KeyValuePair<string, string>>();
for (int i = 0; i < 30; i++)
{
lstHL.Add(new KeyValuePair<string, string>(i.ToString(), "选项" + i));
}
this.ucHorizontalList1.DataSource = lstHL;
this.ucHorizontalList1.DataSource = lstHL;
}
private void timer1_Tick(object sender, EventArgs e)
......@@ -135,5 +135,10 @@ this.ucHorizontalList1.DataSource = lstHL;
frm.ShowDialog(this);
}
private void button9_Click(object sender, EventArgs e)
{
}
}
}
......@@ -18,8 +18,7 @@ namespace Test
}
private void FrmTemp1Test_Load(object sender, EventArgs e)
{
{
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 });
......@@ -27,7 +26,7 @@ namespace Test
this.ucDataGridView1.Columns = lstCulumns;
this.ucDataGridView1.IsShowCheckBox = true;
List<object> lstSource = new List<object>();
for (int i = 0; i < 10; i++)
for (int i = 0; i < 20; i++)
{
TestModel model = new TestModel()
{
......@@ -38,7 +37,9 @@ namespace Test
lstSource.Add(model);
}
this.ucDataGridView1.DataSource = lstSource.ToArray();
UCPagerControl page = new UCPagerControl();
page.DataSource = lstSource;
this.ucDataGridView1.Page = page;
this.ucDataGridView1.First();
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!