Sorry for not being clear with my needs I will elaborate after a quick
explanation of the path I have taken.
I am trying to do exactly as you stated: override the ListView Items
properties Add method. I think I have figured out a way to do it, well kind
of, since as you stated the Items property is not virtual and cannot be
overriden using the override keyword, I used the following syntax to
effectively override it or at least it appears to work as I need it to. It
returns my local__CustomView.Items collection. So now I will just need to
make sure the external Listview.Items collection is updated with the
CustomView.Items collection
new public System.Windows.Forms.ListView.ListViewItemCollecti on Items
{
get
{
//return the __CustomView.Items collection so its collection will be
updated; Don't update the base ListView.Items collection
// we will do that using events as needed in the UI
return __CustomView.Items;
}
}
O.K. now I will try to explain why I am trying to do this. Our app is using
2 listviews
1) to represent our embedded products main features
2) each possible instance of the main feature in the 1st ListView (normally
250 instances per main Feature)
We needed a way to (1)show all possible instances and (2)only the instances
that the user has defined. So effectively show all of the instances or only
show a subset of the possible instances. So I needed a Custom ListView that
I can add all the Items (to store colors and text for each possible
instance) then display the Full set or the subset in a different ListView in
the UI. Since adding Items or changing text(name) and enabled state is done
in various Classes throughout the solution I wanted a separate class that
holds the Items to help keep it "clean" or easy to maintain as we are
constantly updating our embedded products feature set. My next issue will be
to keep the indexes straight between the 2 views as clicking on an Item in
the ListView populates our main UI with that instances data. So in the Full
view the indexes are linear from min to max number of instances and in the
subset view they will be non linear as only defined instances will be
available in the ListView. So index 200 in Full view could be index 2 in
subset view.
I hope this adequately explains what I am trying to do.
Thanks,
Dave
"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:eR**************@TK2MSFTNGP11.phx.gbl...
"Dave Y" wrote...
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().
"Properties" don't have methods.
I think you're confusing the ListView with its property Items in this
case. The method Add doesn't belong to ListView, it belongs to its instance of
ListViewItemCollection, which the property Items returns.
To override "ListView.Items.Add()" you actually would have to overide
*two* classes; One class that inherits the ListView class to "override" the
Items property (which is *not* virtual, so it can't be "truly" overridden), and
a class that inherits ListViewItemCollection to override Add, but...
I can do what I need to do in a different way
this would just make everything significantly
cleaner and eaasier to maintain.
...if you really *told* us what you "need" to do, we probably can help you
find another "clean and easy" way... ;-)
// Bjorn A