473,378 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Inherited ListView

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.

I've got a feeling that it's really quite straight forward. Just can't
see it right now.

Cheers.
Jul 31 '06 #1
5 2495
David Gouge wrote:
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.
You can already add a NewListViewItem to a ListViewItemCollection,
because it's a suclass of ListViewItem. If you want to return them as
well, or do anything meaningful with the parts that are only available
to in the subclass, you'll have to override lots of things in the base
class, and probably write your own NewListViewItemCollection.

Eq.
Jul 31 '06 #2
Paul E Collins wrote:
David Gouge wrote:
>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.

You can already add a NewListViewItem to a ListViewItemCollection,
because it's a suclass of ListViewItem. If you want to return them as
well, or do anything meaningful with the parts that are only available
to in the subclass, you'll have to override lots of things in the base
class, and probably write your own NewListViewItemCollection.

Eq.
Cheers for the reply Paul.

Yeah, that's basically where i got with it. As you say, they add in ok,
but then i have to cast them back out and can't access the new
properties 'inside'.

Any pointers as to 'overriding lots of things' to get it to work? ;)

Cheers!

dave
Jul 31 '06 #3
David Gouge wrote:
Any pointers as to 'overriding lots of things' to get it to work? ;)
Afraid not. I *hate* overriding things whose source code I can't see,
and try to avoid it. I'd probably use a regular ListView (with custom
paint code if you need to draw something special) and store the
metadata in an ArrayList or something, ensuring it's kept synchronised
with the control's contents. Nasty hack, but might save days of work
only to find that the ListView can't be inherited how you intended
(sometimes they don't expose all the things required).

Eq.
Jul 31 '06 #4

"Paul E Collins" wrote...
David Gouge wrote:
>Any pointers as to 'overriding lots of things' to get it to work? ;)

Afraid not. I *hate* overriding things whose source code I can't see, and
try to avoid it. I'd probably use a regular ListView (with custom paint
code if you need to draw something special) and store the metadata in an
ArrayList or something, ensuring it's kept synchronised with the control's
contents. Nasty hack, but might save days of work only to find that the
ListView can't be inherited how you intended (sometimes they don't expose
all the things required).
I'd agree with Paul here, when trying to 'override lots of things' to get it
to work, you'll often end up with overriding almost "everything"...

An alternative to Paul's suggestion of using a "regular" ListView, is
another approach I've often used.

In order to create a public custom control from a pre-built one, I often use
Composition instead of, or in combination with Inheritance, e.g. to put a
ListView onto a UserControl, instead of directly inherit from the ListView.
That way you have better control over what is exposed of your control, e.g.
what type of Items it should accept and return.

/// Bjorn A
Aug 1 '06 #5
Bjorn Abelli wrote:
"Paul E Collins" wrote...
>David Gouge wrote:
>>Any pointers as to 'overriding lots of things' to get it to work? ;)
Afraid not. I *hate* overriding things whose source code I can't see, and
try to avoid it. I'd probably use a regular ListView (with custom paint
code if you need to draw something special) and store the metadata in an
ArrayList or something, ensuring it's kept synchronised with the control's
contents. Nasty hack, but might save days of work only to find that the
ListView can't be inherited how you intended (sometimes they don't expose
all the things required).

I'd agree with Paul here, when trying to 'override lots of things' to get it
to work, you'll often end up with overriding almost "everything"...

An alternative to Paul's suggestion of using a "regular" ListView, is
another approach I've often used.

In order to create a public custom control from a pre-built one, I often use
Composition instead of, or in combination with Inheritance, e.g. to put a
ListView onto a UserControl, instead of directly inherit from the ListView.
That way you have better control over what is exposed of your control, e.g.
what type of Items it should accept and return.
Thanks to you both for the replies. I think i could hear the sharp
intake of breath from here! ;)
Aug 1 '06 #6

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

Similar topics

6
by: VM | last post by:
How can I fill up a listview with text file contents? My listview has two columns and the first column fills up with a while loop: while (myString != null) { myString = sr.Readline();...
1
by: David | last post by:
Hi ListBox, ListView and other controls have inherited methods and properties. I could not understand how to use them. For example if I have protected override void OnClick( System.EventArgs e)...
0
by: keith | last post by:
In a ListView control (two columns), I added a few ListView items. ListView listview=new ListView(); listview.Parent=this; listview.View=View.Details; listview.Columns.Add...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
8
by: Allen Anderson | last post by:
Just curious if there is a way to hide a public member inherited from another class. I know you can 'new' to give it your own version, but is there a way to make it no longer public period? I...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
2
by: Ben H | last post by:
Hello all I'm using a listview in my app but I want to scroll the listview programatically as I hate the look of the standard scrollbar. So, the listview is scrolled programatically using...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.