473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListView in a UserControl

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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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
Aug 10 '06 #1
7 3545
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:

[MergablePropert y(false), Localizable(tru e),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content),
Editor("System. Windows.Forms.D esign.ColumnHea derCollectionEd itor,
System.Design, Version=2.0.0.0 , Culture=neutral ,
PublicKeyToken= b03f5f7f11d50a3 a", typeof(UITypeEd itor)),
SRDescription(" ListViewColumns Descr")]

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

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Laurent Navarro" <yo*@yop.comwro te in message
news:uM******** ******@TK2MSFTN GP06.phx.gbl...
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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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

Aug 10 '06 #2
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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c oma écrit
dans le message de news: uY************* *@TK2MSFTNGP05. phx.gbl...
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:

[MergablePropert y(false), Localizable(tru e),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content),
Editor("System. Windows.Forms.D esign.ColumnHea derCollectionEd itor,
System.Design, Version=2.0.0.0 , Culture=neutral ,
PublicKeyToken= b03f5f7f11d50a3 a", typeof(UITypeEd itor)),
SRDescription(" ListViewColumns Descr")]

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

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Laurent Navarro" <yo*@yop.comwro te in message
news:uM******** ******@TK2MSFTN GP06.phx.gbl...
> 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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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


Aug 10 '06 #3
Have you play with this sample:
http://msdn2.microsoft.com/en-us/lib...ollection.aspx

chanmm

"Laurent Navarro" <yo*@yop.comwro te in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c oma écrit
dans le message de news: uY************* *@TK2MSFTNGP05. phx.gbl...
>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:

[MergablePropert y(false), Localizable(tru e),
DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content),
Editor("System .Windows.Forms. Design.ColumnHe aderCollectionE ditor,
System.Desig n, Version=2.0.0.0 , Culture=neutral ,
PublicKeyToken =b03f5f7f11d50a 3a", typeof(UITypeEd itor)),
SRDescription( "ListViewColumn sDescr")]

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

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Laurent Navarro" <yo*@yop.comwro te in message
news:uM******* *******@TK2MSFT NGP06.phx.gbl.. .
>> 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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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



Aug 10 '06 #4
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" <ch*****@hotmai l.coma écrit dans le message de news:
en************* *@TK2MSFTNGP02. phx.gbl...
Have you play with this sample:
http://msdn2.microsoft.com/en-us/lib...ollection.aspx

chanmm

"Laurent Navarro" <yo*@yop.comwro te in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
> 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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c oma
écrit dans le message de news: uY************* *@TK2MSFTNGP05. phx.gbl...
>>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:

[MergablePropert y(false), Localizable(tru e),
DesignerSeria lizationVisibil ity(DesignerSer ializationVisib ility.Content),
Editor("Syste m.Windows.Forms .Design.ColumnH eaderCollection Editor,
System.Design , Version=2.0.0.0 , Culture=neutral ,
PublicKeyToke n=b03f5f7f11d50 a3a", typeof(UITypeEd itor)),
SRDescription ("ListViewColum nsDescr")]

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

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Laurent Navarro" <yo*@yop.comwro te in message
news:uM****** ********@TK2MSF TNGP06.phx.gbl. ..
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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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



Aug 10 '06 #5

Laurent Navarro wrote:
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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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.

Aug 10 '06 #6
Remove the set() part. You don't need it

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

[MergablePropert y(false), Localizable(tru e),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public ListView.Column HeaderCollectio n MyColumns
{
get
{
return(this.myL istView.Columns );
}
}
/claes

"Laurent Navarro" <yo*@yop.comwro te in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c oma écrit
dans le message de news: uY************* *@TK2MSFTNGP05. phx.gbl...
>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:

[MergablePropert y(false), Localizable(tru e),
DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content),
Editor("System .Windows.Forms. Design.ColumnHe aderCollectionE ditor,
System.Desig n, Version=2.0.0.0 , Culture=neutral ,
PublicKeyToken =b03f5f7f11d50a 3a", typeof(UITypeEd itor)),
SRDescription( "ListViewColumn sDescr")]

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

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Laurent Navarro" <yo*@yop.comwro te in message
news:uM******* *******@TK2MSFT NGP06.phx.gbl.. .
>> 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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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



Aug 10 '06 #7
Thanks Claes !
It's working, there was no need to create a set() function, as you said
!!!

Thanks a lot
"Claes Bergefall" <lo*****@nospam .nospama écrit dans le message de news:
Oq************* *@TK2MSFTNGP04. phx.gbl...
Remove the set() part. You don't need it

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

[MergablePropert y(false), Localizable(tru e),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public ListView.Column HeaderCollectio n MyColumns
{
get
{
return(this.myL istView.Columns );
}
}
/claes

"Laurent Navarro" <yo*@yop.comwro te in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
> 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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c oma
écrit dans le message de news: uY************* *@TK2MSFTNGP05. phx.gbl...
>>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:

[MergablePropert y(false), Localizable(tru e),
DesignerSeria lizationVisibil ity(DesignerSer ializationVisib ility.Content),
Editor("Syste m.Windows.Forms .Design.ColumnH eaderCollection Editor,
System.Design , Version=2.0.0.0 , Culture=neutral ,
PublicKeyToke n=b03f5f7f11d50 a3a", typeof(UITypeEd itor)),
SRDescription ("ListViewColum nsDescr")]

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

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Laurent Navarro" <yo*@yop.comwro te in message
news:uM****** ********@TK2MSF TNGP06.phx.gbl. ..
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.Column HeaderCollectio n myColumns
{
get
{
return(this.myL istView.Columns );
}
set
{
this.myListView .Columns.Clear( );

foreach(Columns Header column in value)
{
this.myListView .Columns.add(co lumn);
}
}

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



Aug 11 '06 #8

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

Similar topics

3
7990
by: Daisy | last post by:
I've started writing a listview, which currently draws my list to a pane, and onclick, works out which row you've clicked on, from the co-ordinates of the mouse, sets the .Selected property to the index of the item in my list, and onpaint, I draw this with a selected box over it. It's dawned on me, that this "list", being just text written...
2
4194
by: Mad Joe | last post by:
Hello! Can someone help me, please? It's 6am, I don't have concentration, feel desperate and I have a deadLine for my project (exam at my university).. How can I display ListView onMouse Click event? Let's say that I just need a detailed view of columnHeaders. Somewhere in my code there is already prepared array:
0
1433
by: Navin | last post by:
Hi, I am making a code editor in C# and want to display line numbers to the left. I have a UserControl with a ListView docked to the left edge and a TextBox that makes up the rest. I am able to add items to the ListView when a new line is entered in the TextBox (these items are the line numbers). What I am not able to figure out is how to...
13
2057
by: **Developer** | last post by:
I need to sort the columns of a ListView. Some columns contain dates and others contain integers. What I did once before is in the Compare method I tried date and if that failed I did Integer. Seems kinda not nice - is there a better way? Thanks
11
1382
by: rb | last post by:
Hi All, Is there a property or method to keep the headercolumns from being resized by the user for a listview? I am using Visual Basic in Visual Studio . net 2005 Thank you.
5
2513
by: David Gouge | last post by:
Hi all, Hope this is a simple one for you but i seem to be having a bit of a mental block. I have an inherited ListView (NewListView) class and an inherited ListViewItem (NewListViewItem) class. How do i get my NewListView class to accept NewListViewItems into and return NewListViewItems from the Items collection.
1
3444
by: --== Alain ==-- | last post by:
Hi, I'm coming back on the ListView component that i would like to design. I finally finish to analyse how it should work (on paper). So i have properties, methods and events that i should implement. I found several points that must base component respects to implement it. - it should implement a canvas/GDI to allow drawing (to allow...
12
4005
by: Tom Bean | last post by:
I am trying to display a ContextMenuStrip when a user right-clicks on an item in a ListView and have encountered a something that seems strange to me. When the ListView is initially populated, no items are selected. When the first item is selected by clicking either the left or right button, the SelectedIndexChanged event fires but not the...
0
930
by: Lloyd Sheen | last post by:
I was in a thread talking about how to populate a listview from a Linq query. This got my curiosity up so I created a usercontrol which is a listview which can be populated from a Linq query. I has all the same properties / methods available to a listview but behind the scenes it is really a virtual listview. It is quick to load (33K items...
0
7827
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8184
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. ...
0
6581
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...
1
5701
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3820
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3845
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1158
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...

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.