Commit bdfee2a5 HZH

修改列表控件清空

1 个父辈 1ab11397
...@@ -125,7 +125,11 @@ namespace HZH_Controls.Controls ...@@ -125,7 +125,11 @@ namespace HZH_Controls.Controls
set set
{ {
if (value == null) if (value == null)
{
m_dataSource = value;
ReloadSource();
return; return;
}
if (!typeof(IList).IsAssignableFrom(value.GetType())) if (!typeof(IList).IsAssignableFrom(value.GetType()))
{ {
throw new Exception("数据源不是有效的数据类型,列表"); throw new Exception("数据源不是有效的数据类型,列表");
...@@ -233,9 +237,12 @@ namespace HZH_Controls.Controls ...@@ -233,9 +237,12 @@ namespace HZH_Controls.Controls
/// </summary> /// </summary>
public void ReloadSource() public void ReloadSource()
{ {
try
{
if (DesignMode) if (DesignMode)
return; return;
ControlHelper.FreezeControl(this, true); ControlHelper.FreezeControl(this, true);
if (this.panMain.Controls.Count <= 0) if (this.panMain.Controls.Count <= 0)
{ {
ReloadGridStyle(); ReloadGridStyle();
...@@ -270,8 +277,13 @@ namespace HZH_Controls.Controls ...@@ -270,8 +277,13 @@ namespace HZH_Controls.Controls
if (this.panMain.Controls[i].Visible) if (this.panMain.Controls[i].Visible)
this.panMain.Controls[i].Visible = false; this.panMain.Controls[i].Visible = false;
} }
}
finally
{
ControlHelper.FreezeControl(this, false); ControlHelper.FreezeControl(this, false);
} }
}
#endregion #endregion
#region 刷新表格 #region 刷新表格
......
...@@ -73,10 +73,22 @@ namespace HZH_Controls.Controls ...@@ -73,10 +73,22 @@ namespace HZH_Controls.Controls
} }
set set
{ {
base.DataSource = value; if (value == null)
if (base.DataSource == null) {
base.DataSource = new List<object>(); base.DataSource = new List<object>();
}
else
{
base.DataSource = value;
}
PageIndex = 1;
ResetPageCount(); ResetPageCount();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} }
} }
......
...@@ -97,11 +97,19 @@ namespace HZH_Controls.Controls ...@@ -97,11 +97,19 @@ namespace HZH_Controls.Controls
get { return m_pageIndex; } get { return m_pageIndex; }
set { m_pageIndex = value; } set { m_pageIndex = value; }
} }
private List<object> dataSource;
/// <summary> /// <summary>
/// 关联的数据源 /// 关联的数据源
/// </summary> /// </summary>
/// <value>The data source.</value> /// <value>The data source.</value>
public virtual List<object> DataSource { get; set; } public virtual List<object> DataSource
{
get { return dataSource; }
set
{
dataSource = value;
}
}
/// <summary> /// <summary>
/// 数据源改变时发生 /// 数据源改变时发生
/// </summary> /// </summary>
...@@ -167,8 +175,6 @@ namespace HZH_Controls.Controls ...@@ -167,8 +175,6 @@ namespace HZH_Controls.Controls
/// </summary> /// </summary>
public virtual void FirstPage() public virtual void FirstPage()
{ {
if (DataSource == null)
return;
startIndex = 0; startIndex = 0;
var s = GetCurrentSource(); var s = GetCurrentSource();
...@@ -182,8 +188,6 @@ namespace HZH_Controls.Controls ...@@ -182,8 +188,6 @@ namespace HZH_Controls.Controls
/// </summary> /// </summary>
public virtual void PreviousPage() public virtual void PreviousPage()
{ {
if (DataSource == null)
return;
if (startIndex == 0) if (startIndex == 0)
return; return;
startIndex -= m_pageSize; startIndex -= m_pageSize;
...@@ -201,8 +205,7 @@ namespace HZH_Controls.Controls ...@@ -201,8 +205,7 @@ namespace HZH_Controls.Controls
/// </summary> /// </summary>
public virtual void NextPage() public virtual void NextPage()
{ {
if (DataSource == null)
return;
if (startIndex + m_pageSize >= DataSource.Count) if (startIndex + m_pageSize >= DataSource.Count)
{ {
return; return;
...@@ -223,7 +226,13 @@ namespace HZH_Controls.Controls ...@@ -223,7 +226,13 @@ namespace HZH_Controls.Controls
public virtual void EndPage() public virtual void EndPage()
{ {
if (DataSource == null) if (DataSource == null)
{
if (ShowSourceChanged != null)
{
ShowSourceChanged(null);
}
return; return;
}
startIndex = DataSource.Count - m_pageSize; startIndex = DataSource.Count - m_pageSize;
if (startIndex < 0) if (startIndex < 0)
startIndex = 0; startIndex = 0;
...@@ -251,7 +260,7 @@ namespace HZH_Controls.Controls ...@@ -251,7 +260,7 @@ namespace HZH_Controls.Controls
/// <returns>List&lt;System.Object&gt;.</returns> /// <returns>List&lt;System.Object&gt;.</returns>
public virtual List<object> GetCurrentSource() public virtual List<object> GetCurrentSource()
{ {
if (DataSource == null) if (DataSource == null || DataSource.Count <= 0)
return null; return null;
int intShowCount = m_pageSize; int intShowCount = m_pageSize;
if (intShowCount + startIndex > DataSource.Count) if (intShowCount + startIndex > DataSource.Count)
......
...@@ -16,6 +16,12 @@ namespace Test ...@@ -16,6 +16,12 @@ namespace Test
public FrmTestListView() public FrmTestListView()
{ {
InitializeComponent(); InitializeComponent();
BtnHelpClick += FrmTestListView_BtnHelpClick;
}
void FrmTestListView_BtnHelpClick(object sender, EventArgs e)
{
this.ucListView1.Page.DataSource = null;
} }
private void FrmTestListView_Load(object sender, EventArgs e) private void FrmTestListView_Load(object sender, EventArgs e)
...@@ -33,5 +39,7 @@ namespace Test ...@@ -33,5 +39,7 @@ namespace Test
//this.ucListView1.DataSource = lstSource; //this.ucListView1.DataSource = lstSource;
} }
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!