ListView now updates when item text changes

This commit is contained in:
Robin 2015-12-12 19:51:54 +00:00
parent 862002e0ef
commit fc4ba9e6be
2 changed files with 35 additions and 1 deletions

View File

@ -1,13 +1,36 @@
using DarkUI.Config;
using System;
using System.Drawing;
namespace DarkUI.Controls
{
public class DarkListItem
{
#region Event Region
public event EventHandler TextChanged;
#endregion
#region Field Region
private string _text;
#endregion
#region Property Region
public string Text { get; set; }
public string Text
{
get { return _text; }
set
{
_text = value;
if (TextChanged != null)
TextChanged(this, new EventArgs());
}
}
public Rectangle Area { get; set; }

View File

@ -95,7 +95,10 @@ namespace DarkUI.Controls
{
// Set the area size of all new items
foreach (DarkListItem item in e.NewItems)
{
item.TextChanged += Item_TextChanged;
UpdateItemSize(item, g);
}
}
// Find the starting index of the new item list and update anything past that
@ -110,6 +113,9 @@ namespace DarkUI.Controls
if (e.OldItems != null)
{
foreach (DarkListItem item in e.NewItems)
item.TextChanged -= Item_TextChanged;
// Find the starting index of the old item list and update anything past that
if (e.OldStartingIndex < (Items.Count - 1))
{
@ -123,6 +129,11 @@ namespace DarkUI.Controls
UpdateContentSize();
}
private void Item_TextChanged(object sender, EventArgs e)
{
UpdateContentSize();
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);