Hello,
We are trying to subclass the ListView control and have a collection of a
class as the Items. Our implementation works at runtime. However at design
time if the user adds elements, we can not see them in the visual studio
designer.
Any help would be appreciated. The class is NameAndId and the collection
property VariableNamesAndIds. We marked it with the
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
attribute to no avail.
Any help would be appreciated.
Stuart
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace OurCompany.ReportComponents
{
/// <summary>
///
/// </summary>
public partial class ResultListView : ListView, IReportComponent
{
/// <summary>
///
/// </summary>
[Serializable]
public class NameAndId
{
private string name;
private string alias;
private int id;
/// <summary>
///
/// </summary>
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
/// <summary>
///
/// </summary>
public string Alias
{
get
{
return alias;
}
set
{
alias = value;
}
}
/// <summary>
///
/// </summary>
public int Id
{
get
{
return id;
}
set
{
id = value;
}
}
}
private List<NameAndIdmyNameAndIdList;
/// <summary>
///
/// </summary>
[Category("OurCategory")]
[Description("Set name of variables and record ids")]
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
public List<NameAndIdVariableNamesAndIds
{
get
{
return myNameAndIdList;
}
set
{
if (!myItemsSet)
{
myNameAndIdList = value;
int count = myNameAndIdList.Count;
ListViewItem item;
for (int i = 0; i < count; ++i)
{
if (!string.IsNullOrEmpty(myNameAndIdList[i].Alias))
{
item = new ListViewItem(myNameAndIdList[i].Alias);
}
else
{
item = new ListViewItem(myNameAndIdList[i].Name);
}
Items.Add(item);
}
myItemsSet = true;
}
}
}
/// <summary>
/// Default Constructor.
/// </summary>
public ResultListView()
{
InitializeComponent();
myFormatString = new StringBuilder("0");
myNameAndIdList = new List<NameAndId>();
Size = new Size(240, 160);
Columns[0].Width = Size.Width / 2;
// Magic number -2 makes the last column take up all remaining space
in the row.
Columns[1].Width = -2;
}
}
}