ListView SubClass Problem

S

Stuart

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(DesignerSerializationVisibility.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<NameAndId> myNameAndIdList;

/// <summary>
///
/// </summary>
[Category("OurCategory")]
[Description("Set name of variables and record ids")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<NameAndId> VariableNamesAndIds
{
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.Alias))
{
item = new ListViewItem(myNameAndIdList.Alias);
}
else
{
item = new ListViewItem(myNameAndIdList.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;
}
}
}
 
A

Ashot Geodakov

Hi,

Can you try to implement NameAndId.ToString() method ans see if it changes
anything?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top