// ***********************************************************************
// Assembly : HZH_Controls
// Created : 08-22-2019
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// 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;
namespace HZH_Controls.Controls
{
///
/// Class UCListView.
/// Implements the
///
///
[DefaultEvent("SelectedItemEvent")]
public partial class UCListView : UserControl
{
///
/// The m int cell width
///
int m_intCellWidth = 130;//单元格宽度
///
/// The m int cell height
///
int m_intCellHeight = 120;//单元格高度
///
/// The m item type
///
private Type m_itemType = typeof(UCListViewItem);
///
/// Gets or sets the type of the item.
///
/// The type of the item.
/// 单元格控件没有继承实现接口IListViewItem
/// 单元格控件没有继承实现接口IListViewItem
[Description("单元格类型,如果无法满足您的需求,你可以自定义单元格控件,并实现接口IListViewItem"), Category("自定义")]
public Type ItemType
{
get { return m_itemType; }
set
{
if (!typeof(IListViewItem).IsAssignableFrom(value) || !value.IsSubclassOf(typeof(Control)))
throw new Exception("单元格控件没有继承实现接口IListViewItem");
m_itemType = value;
}
}
///
/// The m page
///
private UCPagerControlBase m_page = null;
///
/// 翻页控件
///
/// The page.
/// 翻页控件没有继承UCPagerControlBase
/// 翻页控件没有继承UCPagerControlBase
[Description("翻页控件,如果UCPagerControl不满足你的需求,请自定义翻页控件并继承UCPagerControlBase"), Category("自定义")]
public UCPagerControlBase Page
{
get { return m_page; }
set
{
m_page = value;
if (value != null)
{
if (!typeof(IPageControl).IsAssignableFrom(value.GetType()) || !value.GetType().IsSubclassOf(typeof(UCPagerControlBase)))
throw new Exception("翻页控件没有继承UCPagerControlBase");
this.panMain.AutoScroll = false;
panPage.Visible = true;
this.Controls.SetChildIndex(panMain, 0);
m_page.ShowSourceChanged += m_page_ShowSourceChanged;
m_page.Dock = DockStyle.Fill;
this.panPage.Controls.Clear();
this.panPage.Controls.Add(m_page);
GetCellCount();
this.DataSource = m_page.GetCurrentSource();
}
else
{
this.panMain.AutoScroll = true;
m_page = null;
panPage.Visible = false;
}
}
}
///
/// The m data source
///
private object m_dataSource = null;
///
/// Gets or sets the data source.
///
/// The data source.
/// 数据源不是有效的数据类型,列表
/// 数据源不是有效的数据类型,列表
[Description("数据源,如果使用翻页控件,请使用翻页控件的DataSource"), Category("自定义")]
public object DataSource
{
get { return m_dataSource; }
set
{
if (value == null)
{
m_dataSource = value;
ReloadSource();
return;
}
if (!typeof(IList).IsAssignableFrom(value.GetType()))
{
throw new Exception("数据源不是有效的数据类型,列表");
}
m_dataSource = value;
ReloadSource();
}
}
///
/// The m int cell count
///
int m_intCellCount = 0;//单元格总数
///
/// Gets the cell count.
///
/// The cell count.
[Description("单元格总数"), Category("自定义")]
public int CellCount
{
get { return m_intCellCount; }
private set
{
m_intCellCount = value;
if (value > 0 && m_page != null)
{
m_page.PageSize = m_intCellCount;
m_page.Reload();
}
}
}
///
/// The m selected source
///
private List