DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Overriding Columns property of s List

  1. #1
    Traci A Butler Guest

    Overriding Columns property of s List


    I have a sortable ListView control that inherits from a traditional ListView.
    The inherited control makes use of typed column headers (inherited from
    a traditional column header) for sorting the ListView columns based on their
    data types. My issue involves setting properties of this control at design
    time, specifically the Columns property.

    Here is how I am creating my column headers programmatically:
    ' Create columns for the items and subitems.
    Dim objCol1 As New clsTypedColumnHeader(TypeCode.Int16)
    objCol1.Text = "ID"
    SortableListView.Columns.Add(objCol1)

    Dim objCol2 As New clsTypedColumnHeader(TypeCode.DateTime)
    objCol2.Text = "Date"
    SortableListView.Columns.Add(objCol2)

    'etc.

    This works great as long as the columns are created programmatically. I
    can click on any column header in my SortableListView control to sort the
    data according to its type.

    Here's my problem. If the user wants to specify Columns at design
    time through the properties window, the standard ColumnHeader class is used,
    so my sorting will not work properly. Can I override the Columns property
    of the ListView control in my inherited control so that the column headers
    that are added to my ListView are using my new typed column header and not
    the column headers that I inherited from? It appears that the Columns property
    of the base ListView class is not overrideable - but I might be wrong.

    - Traci



  2. #2
    Bill Storage Guest

    Re: Overriding Columns property of s List

    Yes, you can do this. You can either build a custom property editor, or you
    can use a generic object editor.

    To use a generic object editor, your Listview must do the following:

    1. Provide a ReadOnly collection property returning an object that
    implements IList.

    2. The Collection object (e.g. Items) should have public AddRange and Add
    methods that take the specific type of item the collection (e.g. ListItem).

    3. The collection property should have a DesignerSerializationVisibility
    attribute of value "Content".

    4. Each item in the collection (e.g. ListItem) should offer a type converter
    that can perform a ConvertTo to data type InstanceDescriptor. This is needed
    by the IDE code generator to handle saving your design-time-added items.


    This sounds way worse than it is - it isn't much code. I'll have a VS Mag
    article out next month covering this.

    Bill Storage


    "Traci A Butler" <a@b.c> wrote in message news:3c9b94c8$1@10.1.10.29...
    >
    > I have a sortable ListView control that inherits from a traditional

    ListView.
    > The inherited control makes use of typed column headers (inherited from
    > a traditional column header) for sorting the ListView columns based on

    their
    > data types. My issue involves setting properties of this control at

    design
    > time, specifically the Columns property.
    >
    > Here is how I am creating my column headers programmatically:
    > ' Create columns for the items and subitems.
    > Dim objCol1 As New clsTypedColumnHeader(TypeCode.Int16)
    > objCol1.Text = "ID"
    > SortableListView.Columns.Add(objCol1)
    >
    > Dim objCol2 As New clsTypedColumnHeader(TypeCode.DateTime)
    > objCol2.Text = "Date"
    > SortableListView.Columns.Add(objCol2)
    >
    > 'etc.
    >
    > This works great as long as the columns are created programmatically. I
    > can click on any column header in my SortableListView control to sort the
    > data according to its type.
    >
    > Here's my problem. If the user wants to specify Columns at design
    > time through the properties window, the standard ColumnHeader class is

    used,
    > so my sorting will not work properly. Can I override the Columns property
    > of the ListView control in my inherited control so that the column headers
    > that are added to my ListView are using my new typed column header and not
    > the column headers that I inherited from? It appears that the Columns

    property
    > of the base ListView class is not overrideable - but I might be wrong.
    >
    > - Traci
    >
    >




  3. #3
    Traci A Butler Guest

    Re: Overriding Columns property of s List


    I was hoping there was a way to do this without coming up with some cheesy
    work around. I'll be looking for that article too! Thanks,

    Traci


    "Bill Storage" <storage@bplusmylastname.com> wrote:
    >Yes, you can do this. You can either build a custom property editor, or

    you
    >can use a generic object editor.
    >
    >To use a generic object editor, your Listview must do the following:
    >
    >1. Provide a ReadOnly collection property returning an object that
    >implements IList.
    >
    >2. The Collection object (e.g. Items) should have public AddRange and Add
    >methods that take the specific type of item the collection (e.g. ListItem).
    >
    >3. The collection property should have a DesignerSerializationVisibility
    >attribute of value "Content".
    >
    >4. Each item in the collection (e.g. ListItem) should offer a type converter
    >that can perform a ConvertTo to data type InstanceDescriptor. This is needed
    >by the IDE code generator to handle saving your design-time-added items.
    >
    >
    >This sounds way worse than it is - it isn't much code. I'll have a VS Mag
    >article out next month covering this.
    >
    >Bill Storage
    >
    >
    >"Traci A Butler" <a@b.c> wrote in message news:3c9b94c8$1@10.1.10.29...
    >>
    >> I have a sortable ListView control that inherits from a traditional

    >ListView.
    >> The inherited control makes use of typed column headers (inherited from
    >> a traditional column header) for sorting the ListView columns based on

    >their
    >> data types. My issue involves setting properties of this control at

    >design
    >> time, specifically the Columns property.
    >>
    >> Here is how I am creating my column headers programmatically:
    >> ' Create columns for the items and subitems.
    >> Dim objCol1 As New clsTypedColumnHeader(TypeCode.Int16)
    >> objCol1.Text = "ID"
    >> SortableListView.Columns.Add(objCol1)
    >>
    >> Dim objCol2 As New clsTypedColumnHeader(TypeCode.DateTime)
    >> objCol2.Text = "Date"
    >> SortableListView.Columns.Add(objCol2)
    >>
    >> 'etc.
    >>
    >> This works great as long as the columns are created programmatically.

    I
    >> can click on any column header in my SortableListView control to sort

    the
    >> data according to its type.
    >>
    >> Here's my problem. If the user wants to specify Columns at design
    >> time through the properties window, the standard ColumnHeader class is

    >used,
    >> so my sorting will not work properly. Can I override the Columns property
    >> of the ListView control in my inherited control so that the column headers
    >> that are added to my ListView are using my new typed column header and

    not
    >> the column headers that I inherited from? It appears that the Columns

    >property
    >> of the base ListView class is not overrideable - but I might be wrong.
    >>
    >> - Traci
    >>
    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center