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,44 +237,52 @@ namespace HZH_Controls.Controls ...@@ -233,44 +237,52 @@ namespace HZH_Controls.Controls
/// </summary> /// </summary>
public void ReloadSource() public void ReloadSource()
{ {
if (DesignMode) try
return;
ControlHelper.FreezeControl(this, true);
if (this.panMain.Controls.Count <= 0)
{
ReloadGridStyle();
}
if (m_dataSource == null || ((IList)m_dataSource).Count <= 0)
{ {
for (int i = this.panMain.Controls.Count - 1; i >= 0; i--) if (DesignMode)
return;
ControlHelper.FreezeControl(this, true);
if (this.panMain.Controls.Count <= 0)
{ {
this.panMain.Controls[i].Visible = false; ReloadGridStyle();
} }
if (m_dataSource == null || ((IList)m_dataSource).Count <= 0)
{
for (int i = this.panMain.Controls.Count - 1; i >= 0; i--)
{
this.panMain.Controls[i].Visible = false;
}
return; return;
} }
int intCount = Math.Min(((IList)m_dataSource).Count, this.panMain.Controls.Count); int intCount = Math.Min(((IList)m_dataSource).Count, this.panMain.Controls.Count);
for (int i = 0; i < intCount; i++) for (int i = 0; i < intCount; i++)
{
((IListViewItem)this.panMain.Controls[i]).DataSource = ((IList)m_dataSource)[i];
if (m_selectedSource.Contains(((IList)m_dataSource)[i]))
{ {
((IListViewItem)this.panMain.Controls[i]).SetSelected(true); ((IListViewItem)this.panMain.Controls[i]).DataSource = ((IList)m_dataSource)[i];
if (m_selectedSource.Contains(((IList)m_dataSource)[i]))
{
((IListViewItem)this.panMain.Controls[i]).SetSelected(true);
}
else
{
((IListViewItem)this.panMain.Controls[i]).SetSelected(false);
}
this.panMain.Controls[i].Visible = true;
} }
else
for (int i = this.panMain.Controls.Count - 1; i >= intCount; i--)
{ {
((IListViewItem)this.panMain.Controls[i]).SetSelected(false); if (this.panMain.Controls[i].Visible)
this.panMain.Controls[i].Visible = false;
} }
this.panMain.Controls[i].Visible = true;
}
for (int i = this.panMain.Controls.Count - 1; i >= intCount; i--) }
finally
{ {
if (this.panMain.Controls[i].Visible) ControlHelper.FreezeControl(this, false);
this.panMain.Controls[i].Visible = false;
} }
ControlHelper.FreezeControl(this, false);
} }
#endregion #endregion
......
...@@ -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!