ListView in a UserControl

L

Laurent Navarro

Hello,


I'm creating a control including a listview. I would like to be able to
set the columns through the Design Tool in Visual Studio, so I created a
parameter to access the columns of my listview:

private ListView.ColumnHeaderCollection myColumns
{
get
{
return(this.myListView.Columns);
}
set
{
this.myListView.Columns.Clear();

foreach(ColumnsHeader column in value)
{
this.myListView.Columns.add(column);
}
}

Of course this is not working, I can insert my columns in the designer,
but when I launch my application, the collection is empty. I'm sure what I
did is dirty, but I don't know what to do... If someone has a clue...

Thank !

Laurent
 
N

Nicholas Paldino [.NET/C# MVP]

Laurent,

Two things first. One, your property should be public, otherwise, I
don't know how the designer is going to be able to access it.

Two, when you make it public, you will want to name it MyColumns, as per
the public naming convention.

That being said, you need to attach the following attributes to your
MyColumns property:

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),
SRDescription("ListViewColumnsDescr")]

This will enable the property window to help with designing your
columns.

Hope this helps.
 
L

Laurent Navarro

Hi Nicholas !


Thanks for your answer. I tried what you said, and Visual Studio returns
me some error... I use Visual Studio 2003, prehaps this is the point.

Anyway, I see my collection on the parameter window of the designer and
when I click on it I have a wizard which helps me to create new columns. As
far as I don't close the designer, I can see my columns on my form painted
on Visual Studio. But when I launch my application or close/reopen the
designer, I have lost all my columns.

I guess the set() part of my parameter is wrong, but I don't know what
to do...

Thanks again ! :)





Nicholas Paldino said:
Laurent,

Two things first. One, your property should be public, otherwise, I
don't know how the designer is going to be able to access it.

Two, when you make it public, you will want to name it MyColumns, as
per the public naming convention.

That being said, you need to attach the following attributes to your
MyColumns property:

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),
SRDescription("ListViewColumnsDescr")]

This will enable the property window to help with designing your
columns.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Laurent Navarro said:
Hello,


I'm creating a control including a listview. I would like to be able
to set the columns through the Design Tool in Visual Studio, so I created
a parameter to access the columns of my listview:

private ListView.ColumnHeaderCollection myColumns
{
get
{
return(this.myListView.Columns);
}
set
{
this.myListView.Columns.Clear();

foreach(ColumnsHeader column in value)
{
this.myListView.Columns.add(column);
}
}

Of course this is not working, I can insert my columns in the
designer, but when I launch my application, the collection is empty. I'm
sure what I did is dirty, but I don't know what to do... If someone has a
clue...

Thank !

Laurent
 
C

chanmm

Have you play with this sample:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.columnheadercollection.aspx

chanmm

Laurent Navarro said:
Hi Nicholas !


Thanks for your answer. I tried what you said, and Visual Studio
returns me some error... I use Visual Studio 2003, prehaps this is the
point.

Anyway, I see my collection on the parameter window of the designer and
when I click on it I have a wizard which helps me to create new columns.
As far as I don't close the designer, I can see my columns on my form
painted on Visual Studio. But when I launch my application or close/reopen
the designer, I have lost all my columns.

I guess the set() part of my parameter is wrong, but I don't know what
to do...

Thanks again ! :)





Nicholas Paldino said:
Laurent,

Two things first. One, your property should be public, otherwise, I
don't know how the designer is going to be able to access it.

Two, when you make it public, you will want to name it MyColumns, as
per the public naming convention.

That being said, you need to attach the following attributes to your
MyColumns property:

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),
SRDescription("ListViewColumnsDescr")]

This will enable the property window to help with designing your
columns.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Laurent Navarro said:
Hello,


I'm creating a control including a listview. I would like to be able
to set the columns through the Design Tool in Visual Studio, so I
created a parameter to access the columns of my listview:

private ListView.ColumnHeaderCollection myColumns
{
get
{
return(this.myListView.Columns);
}
set
{
this.myListView.Columns.Clear();

foreach(ColumnsHeader column in value)
{
this.myListView.Columns.add(column);
}
}

Of course this is not working, I can insert my columns in the
designer, but when I launch my application, the collection is empty. I'm
sure what I did is dirty, but I don't know what to do... If someone has
a clue...

Thank !

Laurent
 
L

Laurent Navarro

Yep, I saw this sample. I'm sure I can do it by hard coding the names of
my columns, but I would like my control to be fully compatible with the
Visual Studio Designer, ie being able to define the columns using the
wizard...

Thanks anyway ! :)



chanmm said:
Have you play with this sample:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.columnheadercollection.aspx

chanmm

Laurent Navarro said:
Hi Nicholas !


Thanks for your answer. I tried what you said, and Visual Studio
returns me some error... I use Visual Studio 2003, prehaps this is the
point.

Anyway, I see my collection on the parameter window of the designer
and when I click on it I have a wizard which helps me to create new
columns. As far as I don't close the designer, I can see my columns on my
form painted on Visual Studio. But when I launch my application or
close/reopen the designer, I have lost all my columns.

I guess the set() part of my parameter is wrong, but I don't know what
to do...

Thanks again ! :)





Nicholas Paldino said:
Laurent,

Two things first. One, your property should be public, otherwise, I
don't know how the designer is going to be able to access it.

Two, when you make it public, you will want to name it MyColumns, as
per the public naming convention.

That being said, you need to attach the following attributes to your
MyColumns property:

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),
SRDescription("ListViewColumnsDescr")]

This will enable the property window to help with designing your
columns.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Hello,


I'm creating a control including a listview. I would like to be able
to set the columns through the Design Tool in Visual Studio, so I
created a parameter to access the columns of my listview:

private ListView.ColumnHeaderCollection myColumns
{
get
{
return(this.myListView.Columns);
}
set
{
this.myListView.Columns.Clear();

foreach(ColumnsHeader column in value)
{
this.myListView.Columns.add(column);
}
}

Of course this is not working, I can insert my columns in the
designer, but when I launch my application, the collection is empty.
I'm sure what I did is dirty, but I don't know what to do... If someone
has a clue...

Thank !

Laurent
 
B

Bruce Wood

Laurent said:
Hello,


I'm creating a control including a listview. I would like to be able to
set the columns through the Design Tool in Visual Studio, so I created a
parameter to access the columns of my listview:

private ListView.ColumnHeaderCollection myColumns
{
get
{
return(this.myListView.Columns);
}
set
{
this.myListView.Columns.Clear();

foreach(ColumnsHeader column in value)
{
this.myListView.Columns.add(column);
}
}

Of course this is not working, I can insert my columns in the designer,
but when I launch my application, the collection is empty. I'm sure what I
did is dirty, but I don't know what to do... If someone has a clue...

Thank !

Laurent

Did you try looking at the code that the Designer wrote as a result?
Please post the code that the Designer writes when you insert, say,
three columns into your list view column collection. Once we see that,
we can probably tell you why your collection is empty at run time.
 
C

Claes Bergefall

Remove the set() part. You don't need it

I think Nicholas assumed you were using 2.0 (the
ColumnHeaderCollectionEditor doesn't seem to exist in 1.1). Try with this

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ListView.ColumnHeaderCollection MyColumns
{
get
{
return(this.myListView.Columns);
}
}


/claes

Laurent Navarro said:
Hi Nicholas !


Thanks for your answer. I tried what you said, and Visual Studio
returns me some error... I use Visual Studio 2003, prehaps this is the
point.

Anyway, I see my collection on the parameter window of the designer and
when I click on it I have a wizard which helps me to create new columns.
As far as I don't close the designer, I can see my columns on my form
painted on Visual Studio. But when I launch my application or close/reopen
the designer, I have lost all my columns.

I guess the set() part of my parameter is wrong, but I don't know what
to do...

Thanks again ! :)





Nicholas Paldino said:
Laurent,

Two things first. One, your property should be public, otherwise, I
don't know how the designer is going to be able to access it.

Two, when you make it public, you will want to name it MyColumns, as
per the public naming convention.

That being said, you need to attach the following attributes to your
MyColumns property:

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),
SRDescription("ListViewColumnsDescr")]

This will enable the property window to help with designing your
columns.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Laurent Navarro said:
Hello,


I'm creating a control including a listview. I would like to be able
to set the columns through the Design Tool in Visual Studio, so I
created a parameter to access the columns of my listview:

private ListView.ColumnHeaderCollection myColumns
{
get
{
return(this.myListView.Columns);
}
set
{
this.myListView.Columns.Clear();

foreach(ColumnsHeader column in value)
{
this.myListView.Columns.add(column);
}
}

Of course this is not working, I can insert my columns in the
designer, but when I launch my application, the collection is empty. I'm
sure what I did is dirty, but I don't know what to do... If someone has
a clue...

Thank !

Laurent
 
L

Laurent Navarro

Thanks Claes !


It's working, there was no need to create a set() function, as you said
!!!

Thanks a lot


Claes Bergefall said:
Remove the set() part. You don't need it

I think Nicholas assumed you were using 2.0 (the
ColumnHeaderCollectionEditor doesn't seem to exist in 1.1). Try with this

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ListView.ColumnHeaderCollection MyColumns
{
get
{
return(this.myListView.Columns);
}
}


/claes

Laurent Navarro said:
Hi Nicholas !


Thanks for your answer. I tried what you said, and Visual Studio
returns me some error... I use Visual Studio 2003, prehaps this is the
point.

Anyway, I see my collection on the parameter window of the designer
and when I click on it I have a wizard which helps me to create new
columns. As far as I don't close the designer, I can see my columns on my
form painted on Visual Studio. But when I launch my application or
close/reopen the designer, I have lost all my columns.

I guess the set() part of my parameter is wrong, but I don't know what
to do...

Thanks again ! :)





Nicholas Paldino said:
Laurent,

Two things first. One, your property should be public, otherwise, I
don't know how the designer is going to be able to access it.

Two, when you make it public, you will want to name it MyColumns, as
per the public naming convention.

That being said, you need to attach the following attributes to your
MyColumns property:

[MergableProperty(false), Localizable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),
SRDescription("ListViewColumnsDescr")]

This will enable the property window to help with designing your
columns.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Hello,


I'm creating a control including a listview. I would like to be able
to set the columns through the Design Tool in Visual Studio, so I
created a parameter to access the columns of my listview:

private ListView.ColumnHeaderCollection myColumns
{
get
{
return(this.myListView.Columns);
}
set
{
this.myListView.Columns.Clear();

foreach(ColumnsHeader column in value)
{
this.myListView.Columns.add(column);
}
}

Of course this is not working, I can insert my columns in the
designer, but when I launch my application, the collection is empty.
I'm sure what I did is dirty, but I don't know what to do... If someone
has a clue...

Thank !

Laurent
 

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