473,657 Members | 2,445 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 VariableNamesAn dIds. We marked it with the
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
attribute to no avail.

Any help would be appreciated.

Stuart

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows. Forms;

namespace OurCompany.Repo rtComponents
{
/// <summary>
///
/// </summary>
public partial class ResultListView : ListView, IReportComponen t
{
/// <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<NameAndIdm yNameAndIdList;

/// <summary>
///
/// </summary>
[Category("OurCa tegory")]
[Description("Se t name of variables and record ids")]
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public List<NameAndIdV ariableNamesAnd Ids
{
get
{
return myNameAndIdList ;
}
set
{
if (!myItemsSet)
{
myNameAndIdList = value;
int count = myNameAndIdList .Count;
ListViewItem item;
for (int i = 0; i < count; ++i)
{
if (!string.IsNull OrEmpty(myNameA ndIdList[i].Alias))
{
item = new ListViewItem(my NameAndIdList[i].Alias);
}
else
{
item = new ListViewItem(my NameAndIdList[i].Name);
}
Items.Add(item) ;
}
myItemsSet = true;
}

}
}
/// <summary>
/// Default Constructor.
/// </summary>
public ResultListView( )
{
InitializeCompo nent();
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 2897
Hi,

Can you try to implement NameAndId.ToStr ing() method ans see if it changes
anything?
"Stuart" <fi********@new sgroups.nospamw rote in message
news:AB******** *************** ***********@mic rosoft.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 VariableNamesAn dIds. We marked it with the
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
attribute to no avail.

Any help would be appreciated.

Stuart

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows. Forms;

namespace OurCompany.Repo rtComponents
{
/// <summary>
///
/// </summary>
public partial class ResultListView : ListView, IReportComponen t
{
/// <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<NameAndIdm yNameAndIdList;

/// <summary>
///
/// </summary>
[Category("OurCa tegory")]
[Description("Se t name of variables and record ids")]

[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public List<NameAndIdV ariableNamesAnd Ids
{
get
{
return myNameAndIdList ;
}
set
{
if (!myItemsSet)
{
myNameAndIdList = value;
int count = myNameAndIdList .Count;
ListViewItem item;
for (int i = 0; i < count; ++i)
{
if (!string.IsNull OrEmpty(myNameA ndIdList[i].Alias))
{
item = new ListViewItem(my NameAndIdList[i].Alias);
}
else
{
item = new ListViewItem(my NameAndIdList[i].Name);
}
Items.Add(item) ;
}
myItemsSet = true;
}

}
}
/// <summary>
/// Default Constructor.
/// </summary>
public ResultListView( )
{
InitializeCompo nent();
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
1346
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 subclass the control? thanks ThunderMusic
6
1518
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 for ListView control, anyone know how can I achieve that? Thanks, Tee
2
12517
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#. Autoscroll is enabled. Also, I need to know if the user scrolls the ListView horizontally. Thanks,
1
5623
by: Sam Martin | last post by:
hi all, anyone know how i can detect this i c#? tia sam martin
19
25450
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 sort columns based on the column header the user has clicked in both Ascending and Descending formats.
5
2363
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 fullrowselect=true in the listview Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, _
1
2290
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 Compact Framework controls. The links are: http://blog.opennetcf.org/ayakhnin/CategoryView.aspx?category=ListView http://blogs.msdn.com/netcfteam/archive/2005/07/24/442616.aspx Sub-classing allows you to trap windows messages and provide...
4
13161
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 associated IList/Collection . Once I've sorted the ListView, obviously the indices do not match up anymore. So, should i sort the IList/Collection when I sort the ListView (which seems overkill to me) or some how sort the indices associated with the...
0
1233
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 in order to accomplish a right click on a listview column header, I need to subclass the listview class and override the WndProc function. I've never done this so I'm not sure how to do it. Does anyone have this done already or provide some sample...
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.