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 (NewListViewIte m) class. How do i get my NewListView class
to accept NewListViewItem s into and return NewListViewItem s from the
Items collection.
I've got a feeling that it's really quite straight forward. Just can't
see it right now.
Cheers. 5 2513
David Gouge wrote:
I have an inherited ListView (NewListView) class and
an inherited ListViewItem (NewListViewIte m) class.
How do i get my NewListView class to accept
NewListViewItem s into and return NewListViewItem s
from the Items collection.
You can already add a NewListViewItem to a ListViewItemCol lection,
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 NewListViewItem Collection.
Eq.
Paul E Collins wrote:
David Gouge wrote:
>I have an inherited ListView (NewListView) class and an inherited ListViewItem (NewListViewIte m) class. How do i get my NewListView class to accept NewListViewIte ms into and return NewListViewItem s from the Items collection.
You can already add a NewListViewItem to a ListViewItemCol lection,
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 NewListViewItem Collection.
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
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.
"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
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! ;) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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();
listView1.Items.Add (myString);
}
Is there a way I can fill up the second column this easily? Thw way I'm currently doing it is using the subitems property to add it. Unfortunately,
|
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)
{
//.......
base.OnClick(e);
}
|
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
("Col1",200,HorizontalAlignment.Left);
listview.Columns.Add
("Col2",800,HorizontalAlignment.Left);
|
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 ListView.Items.Add(), . I see
that it is a virtual method so it should be easy to do. If anyone can help I
would appreciate it greatly. I can do what I need to do in a different way
this would just make everything significantly cleaner and eaasier...
|
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 would like the
base class version to stay there, just be protected instead. I can't
make the baseclass version protected because there are times when the
baseclass can be used by itself.
| |
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 MyList data is resident
in a dataset table.
I'm stuck and can't choose either because.
If I choose ListView as my control I don't understand how
to programmatically get the data from the dataset table
|
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 ensurevisible, ie the
listview shows a maximum of 6 items and if I want to scroll down one I use
the code...
listview.ensurevisible(listview.TopItem.Index + 6)
|
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 form every thing works fine: checking items by code
|
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 is that when clicking on the
"Show details" button the ListView for the appropriate row binds in the
codebehind and displays the detail data for the selected row. I did
something similar with a gridview control previously, but want to be able to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |