468,512 Members | 1,346 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

custom listview control

I know the following code is C#. I'm a vb programmer trying to learn a new language. I posted this in the c# group but never got a response. You guys seem to know alot about all languages and have all the answers, so here it is..

I'm trying to create a custom listview that uses custom listviewitems. The listviewitems persist just fine in design mode. However, when I build the solution, the listview item doesn't show up. I've run some tests, and the item is still there. However, it's not displayed on the ui

Am I missing something simple? It's still there--why isn't it showing up

Once again, thank you, and sorry about the c#
Tod

Here's my code..

using System
using System.Collections
using System.ComponentModel
using System.ComponentModel.Design
using System.Drawing
using System.Drawing.Design
using System.Data
using System.Windows.Forms
using System.Windows.Forms.Design

namespace ST

[ToolboxItem(true)
public class ListViewEx : System.Windows.Forms.ListVie
{
private ListViewItemCollectionEx m_colItems

public ListViewEx(

SetStyle(ControlStyles.ResizeRedraw, true)
SetStyle(ControlStyles.AllPaintingInWmPaint, true)
SetStyle(ControlStyles.DoubleBuffer, true)

m_colItems = new ListViewItemCollectionEx(this);
[Browsable(true)
[Category("Behavior")
[Description("The items in the ListView.")
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)
Editor(typeof(CollectionEditor), typeof(UITypeEditor))
public new ListViewItemCollectionEx Item

get { return m_colItems;

[Serializable()
public class ListViewItemCollectionEx : System.Windows.Forms.ListView.ListViewItemCollecti o
{
private ListViewEx m_objParent

public ListViewItemCollectionEx(ListViewEx owner) : base(owner

// Set reference to parent ListViewEx
this.m_objParent = owner
public new ListViewItemEx this[int Index

get { return (ListViewItemEx) base[Index];
public void Add(ListViewItemEx objListViewItemEx

base.Add(objListViewItemEx)

// Give item a reference to parent listview
objListViewItemEx.m_objParent = this.m_objParent
public bool Contains(ListViewItemEx objListViewItemEx

return base.Contains(objListViewItemEx)
public void Remove(ListViewItemEx objListViewItemEx

// Remove item from listview
base.Remove(objListViewItemEx)

// Remove items reference to parent
objListViewItemEx.m_objParent = null;
public void IndexOf(ListViewItemEx objListViewItemEx

base.IndexOf(objListViewItemEx)

[Serializable()
[ToolboxItem(false)
[TypeConverter("STS.ListViewItemExConverter")
public class ListViewItemEx : System.Windows.Forms.ListViewIte
{
internal ListViewEx m_objParent

public ListViewItemEx() : base(

public class ListViewItemExConverter : System.ComponentModel.TypeConverte

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType

if (destinationType == typeof(InstanceDescriptor)

return true
return base.CanConvertTo(context, destinationType)
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType
{
if (destinationType == typeof(InstanceDescriptor) && value is ListViewItemEx
{
ListViewItemEx lvi = (ListViewItemEx)value;
ConstructorInfo ci = typeof(ListViewItemEx).GetConstructor(new Type[] {})
if (ci != null) return new InstanceDescriptor(ci, null, false)
return base.ConvertTo(context, culture, value, destinationType)

Nov 20 '05 #1
5 5500
Is your list view in "large icon" mode? That is the default property -
change it to "details" and your item might show up.

"ToddH" <an*******@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I know the following code is C#. I'm a vb programmer trying to learn a new language. I posted this in the c# group but never got a response. You guys
seem to know alot about all languages and have all the answers, so here it
is...
I'm trying to create a custom listview that uses custom listviewitems. The listviewitems persist just fine in design mode. However, when I build the
solution, the listview item doesn't show up. I've run some tests, and the
item is still there. However, it's not displayed on the ui.
Am I missing something simple? It's still there--why isn't it showing up?

Once again, thank you, and sorry about the c#,
Todd

Here's my code...

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace STS
{
[ToolboxItem(true)]
public class ListViewEx : System.Windows.Forms.ListView
{
private ListViewItemCollectionEx m_colItems;

public ListViewEx()
{
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);

m_colItems = new ListViewItemCollectionEx(this);
}

[Browsable(true)]
[Category("Behavior")]
[Description("The items in the ListView.")]
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public new ListViewItemCollectionEx Items
{
get { return m_colItems; }
}
}

[Serializable()]
public class ListViewItemCollectionEx : System.Windows.Forms.ListView.ListViewItemCollecti on {
private ListViewEx m_objParent;

public ListViewItemCollectionEx(ListViewEx owner) : base(owner)
{
// Set reference to parent ListViewEx.
this.m_objParent = owner;
}

public new ListViewItemEx this[int Index]
{
get { return (ListViewItemEx) base[Index]; }
}

public void Add(ListViewItemEx objListViewItemEx)
{
base.Add(objListViewItemEx);

// Give item a reference to parent listview.
objListViewItemEx.m_objParent = this.m_objParent;
}

public bool Contains(ListViewItemEx objListViewItemEx)
{
return base.Contains(objListViewItemEx);
}

public void Remove(ListViewItemEx objListViewItemEx)
{
// Remove item from listview.
base.Remove(objListViewItemEx);

// Remove items reference to parent.
objListViewItemEx.m_objParent = null;
}

public void IndexOf(ListViewItemEx objListViewItemEx)
{
base.IndexOf(objListViewItemEx);
}
}

[Serializable()]
[ToolboxItem(false)]
[TypeConverter("STS.ListViewItemExConverter")]
public class ListViewItemEx : System.Windows.Forms.ListViewItem
{
internal ListViewEx m_objParent;

public ListViewItemEx() : base()
{
}

}

public class ListViewItemExConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}

return base.CanConvertTo(context, destinationType);
}

public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type
destinationType) {
if (destinationType == typeof(InstanceDescriptor) && value is ListViewItemEx) {
ListViewItemEx lvi = (ListViewItemEx)value;
ConstructorInfo ci = typeof(ListViewItemEx).GetConstructor(new Type[] {});
if (ci != null) return new InstanceDescriptor(ci, null, false);
}

return base.ConvertTo(context, culture, value, destinationType);
}
}

}

Nov 20 '05 #2
It doesn't work in any mode. Also, that wouldn't make it disappear when I compile or run it. I can see the items in design mode before I build it--no matter what mode. But running it makes the items not repaint. Bizarre

Todd
Nov 20 '05 #3
Are you executing a "clear" in code at all? Often, its possible to "clear"
the columns by mistake, when you just want to clear the items. Well, these
are the 2 reasons I have discovered for the annoying "missing items" problem
in VB.NET. I can't think of any more ;)

"ToddH" <an*******@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
It doesn't work in any mode. Also, that wouldn't make it disappear when I compile or run it. I can see the items in design mode before I build it--no
matter what mode. But running it makes the items not repaint. Bizarre.
Todd

Nov 20 '05 #4
Nope. I'm not doing anthing to the items. In fact, I add them through the collection editor at design-time. After that, I'm not touching them

Todd
Nov 20 '05 #5
Check they are in the collection at runtime with a breakpoint - check the
items.count property.

"ToddH" <an*******@discussions.microsoft.com> wrote in message
news:58**********************************@microsof t.com...
Nope. I'm not doing anthing to the items. In fact, I add them through the collection editor at design-time. After that, I'm not touching them.
Todd

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Simon Middlemiss | last post: by
1 post views Thread by Jeff | last post: by
reply views Thread by Piotr Strycharz | last post: by
7 posts views Thread by =?Utf-8?B?YnJhaW5mdWVsbWVkaWE=?= | last post: by
1 post views Thread by a | last post: by
5 posts views Thread by Mark Olbert | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.