473,505 Members | 13,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListView SubClass Problem

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;
}
}
}

Feb 27 '07 #1
1 2891
Hi,

Can you try to implement NameAndId.ToString() method ans see if it changes
anything?
"Stuart" <fi********@newsgroups.nospamwrote in message
news:AB**********************************@microsof t.com...
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;
}
}
}

Feb 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1329
by: ThunderMusic | last post by:
Hi, I have a problem using the Listview. I want it to display the horizontal scrollbar whenever the data in it goes beyond the right side. Is there a property to do it? Some code, etc. Must I...
6
1510
by: Tee | last post by:
Hi, I have a listview control that has a column displaying path. I need to change the StringTrimming of text in this column to StringTrimming.EllipsisPath, but there is no paint event available...
2
12507
by: Gary Brown | last post by:
Hi, How do you programmatically scroll a ListView control horizontally? (The same effect as if the user used the horizontal scroll bar,) I've done it in C++/MFC, but can't find the means in C#. ...
1
5600
by: Sam Martin | last post by:
hi all, anyone know how i can detect this i c#? tia sam martin
19
25424
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
5
2358
by: Martin Horn | last post by:
Hi all, I want to implement a listview with editable subitems and I assume the easiest way is to overlay a textbox over the item to be edited. With this in mind I have come up with: Using...
1
2279
by: Steamboat | last post by:
I have read two excellent articles on how to subclass .NET controls so that you can hook into the control’s WndProc, which is very helpful since you cannot access the WndProc directly for .NET...
4
13150
by: forest demon | last post by:
I have an IList/Collection that contains items in a ListView. If i click on an item in the ListView, i can capture the index (lv.SelectedItems.Index) and reference the correct item in the...
0
1218
by: da3vilgenius | last post by:
I have a listview and I'd like to be able to do some stuff on a right click event of the column header but the columnclick event only handles left clicks. I looked around on the net and found that...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.