custom listview control

G

Guest

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(DesignerSerializationVisibility.Content)
Editor(typeof(CollectionEditor), typeof(UITypeEditor))
public new ListViewItemCollectionEx Item

get { return m_colItems;



[Serializable()
public class ListViewItemCollectionEx : System.Windows.Forms.ListView.ListViewItemCollectio
{
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)
 
R

Robin Tucker

Is your list view in "large icon" mode? That is the default property -
change it to "details" and your item might show up.

ToddH said:
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(DesignerSerializationVisibility.Content),
Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public new ListViewItemCollectionEx Items
{
get { return m_colItems; }
}
}

[Serializable()]
public class ListViewItemCollectionEx : System.Windows.Forms.ListView.ListViewItemCollection
{
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);
}
}

}
 
G

Guest

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
 
R

Robin Tucker

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 said:
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.
 
G

Guest

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
 
R

Robin Tucker

Check they are in the collection at runtime with a breakpoint - check the
items.count property.

ToddH said:
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.
 

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