Commit 5452207c HZH

listview bug

1 个父辈 2721a706
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
this.Margin = new System.Windows.Forms.Padding(0); this.Margin = new System.Windows.Forms.Padding(0);
this.Name = "UCListView"; this.Name = "UCListView";
this.Size = new System.Drawing.Size(462, 363); this.Size = new System.Drawing.Size(462, 363);
this.Load += new System.EventHandler(this.UCListView_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
......
...@@ -80,7 +80,7 @@ namespace HZH_Controls.Controls ...@@ -80,7 +80,7 @@ namespace HZH_Controls.Controls
{ {
throw new Exception("数据源不是有效的数据类型,列表"); throw new Exception("数据源不是有效的数据类型,列表");
} }
m_dataSource = value; m_dataSource = value;
ReloadSource(); ReloadSource();
} }
} }
...@@ -149,6 +149,10 @@ namespace HZH_Controls.Controls ...@@ -149,6 +149,10 @@ namespace HZH_Controls.Controls
public void ReloadSource() public void ReloadSource()
{ {
ControlHelper.FreezeControl(this, true); ControlHelper.FreezeControl(this, true);
if (this.panMain.Controls.Count <= 0)
{
ReloadGridStyle();
}
if (m_dataSource == null || ((IList)m_dataSource).Count <= 0) if (m_dataSource == null || ((IList)m_dataSource).Count <= 0)
{ {
for (int i = this.panMain.Controls.Count - 1; i >= 0; i--) for (int i = this.panMain.Controls.Count - 1; i >= 0; i--)
...@@ -192,7 +196,6 @@ namespace HZH_Controls.Controls ...@@ -192,7 +196,6 @@ namespace HZH_Controls.Controls
/// </summary> /// </summary>
public void ReloadGridStyle() public void ReloadGridStyle()
{ {
Form frmMain = this.FindForm(); Form frmMain = this.FindForm();
if (frmMain != null && !frmMain.IsDisposed && frmMain.Visible && this.Visible) if (frmMain != null && !frmMain.IsDisposed && frmMain.Visible && this.Visible)
{ {
...@@ -241,41 +244,41 @@ namespace HZH_Controls.Controls ...@@ -241,41 +244,41 @@ namespace HZH_Controls.Controls
void UCListView_SelectedItemEvent(object sender, EventArgs e) void UCListView_SelectedItemEvent(object sender, EventArgs e)
{ {
var selectedItem = sender as IListViewItem; var selectedItem = sender as IListViewItem;
if (m_selectedSource.Contains(selectedItem.DataSource)) if (m_selectedSource.Contains(selectedItem.DataSource))
{
m_selectedSource.Remove(selectedItem.DataSource);
selectedItem.SetSelected(false);
}
else
{
if (m_isMultiple)
{ {
m_selectedSource.Remove(selectedItem.DataSource); m_selectedSource.Add(selectedItem.DataSource);
selectedItem.SetSelected(false); selectedItem.SetSelected(true);
} }
else else
{ {
if (m_isMultiple) if (m_selectedSource.Count > 0)
{ {
m_selectedSource.Add(selectedItem.DataSource); int intCount = Math.Min(((IList)m_dataSource).Count, this.panMain.Controls.Count);
selectedItem.SetSelected(true); for (int i = 0; i < intCount; i++)
}
else
{
if (m_selectedSource.Count > 0)
{ {
int intCount = Math.Min(((IList)m_dataSource).Count, this.panMain.Controls.Count); var item = ((IListViewItem)this.panMain.Controls[i]);
for (int i = 0; i < intCount; i++) if (m_selectedSource.Contains(item.DataSource))
{ {
var item = ((IListViewItem)this.panMain.Controls[i]); item.SetSelected(false);
if (m_selectedSource.Contains(item.DataSource)) break;
{
item.SetSelected(false);
break;
}
} }
} }
}
m_selectedSource = new List<object>() { selectedItem.DataSource }; m_selectedSource = new List<object>() { selectedItem.DataSource };
selectedItem.SetSelected(true); selectedItem.SetSelected(true);
}
}
}
}
if (SelectedItemEvent != null) if (SelectedItemEvent != null)
{ {
SelectedItemEvent(sender, e); SelectedItemEvent(sender, e);
...@@ -296,12 +299,25 @@ namespace HZH_Controls.Controls ...@@ -296,12 +299,25 @@ namespace HZH_Controls.Controls
return; return;
Control item = (Control)Activator.CreateInstance(m_itemType); Control item = (Control)Activator.CreateInstance(m_itemType);
int intXCount = (this.panMain.Width - 10) / (item.Width + 10); int intXCount = (this.panMain.Width - 10) / (item.Width + 10);
m_intCellWidth = item.Width + ((this.panMain.Width - 10) % (item.Width + 10)) / intXCount; m_intCellWidth = item.Width + ((this.panMain.Width - 10) % (item.Width + 10)) / intXCount;
int intYCount = (this.panMain.Height - 10) / (item.Height + 10); int intYCount = (this.panMain.Height - 10) / (item.Height + 10);
m_intCellHeight = item.Height + ((this.panMain.Height - 10) % (item.Height + 10)) / intYCount; m_intCellHeight = item.Height + ((this.panMain.Height - 10) % (item.Height + 10)) / intYCount;
CellCount = intXCount * intYCount; int intCount = intXCount * intYCount;
if (Page == null)
{
if (((IList)m_dataSource).Count > intCount)
{
intXCount = (this.panMain.Width - 10 - 20) / (item.Width + 10);
m_intCellWidth = item.Width + ((this.panMain.Width - 10 - 20) % (item.Width + 10)) / intXCount;
}
intCount = Math.Max(intCount, ((IList)m_dataSource).Count);
}
CellCount = intCount;
} }
#endregion #endregion
...@@ -309,5 +325,10 @@ namespace HZH_Controls.Controls ...@@ -309,5 +325,10 @@ namespace HZH_Controls.Controls
{ {
ReloadGridStyle(); ReloadGridStyle();
} }
private void UCListView_Load(object sender, EventArgs e)
{
}
} }
} }
...@@ -21,7 +21,7 @@ namespace Test ...@@ -21,7 +21,7 @@ namespace Test
private void FrmTestListView_Load(object sender, EventArgs e) private void FrmTestListView_Load(object sender, EventArgs e)
{ {
List<object> lstSource = new List<object>(); List<object> lstSource = new List<object>();
for (int i = 0; i < 1000; i++) for (int i = 0; i < 200; i++)
{ {
lstSource.Add("项-" + i); lstSource.Add("项-" + i);
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!