Click here to Skip to main content
13,453,944 members (45,933 online)
Click here to Skip to main content


26 bookmarked
Posted 14 May 2009

Extending the ListViewItem

, 14 May 2009
How to extend the ListViewItem to hold an object for a row, and map it to the columns in the ListView control.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ListViewExtendedItem
    public partial class mainForm : Form
        public mainForm()
            colID.Name = "colID";
            colName.Name = "colName";
            colDate.Name = "colDate";

        private void btnNew_Click(object sender, EventArgs e)
            TestClass testObject = new TestClass(1, "Some name", DateTime.Now);
            objectPropGrid.SelectedObject = testObject;
            btnAdd.Enabled = true;

        private void objectList_SelectedIndexChanged(object sender, EventArgs e)
            if (objectList.SelectedItems.Count == 1)
                btnUpdate.Enabled = true;
                ListViewExtendedItem item = (ListViewExtendedItem)objectList.SelectedItems[0];
                objectPropGrid.SelectedObject = item.Data;

        private void btnAdd_Click(object sender, EventArgs e)
            btnAdd.Enabled = false;
            ListViewExtendedItem item = new ListViewExtendedItem(objectList, objectPropGrid.SelectedObject);
            objectPropGrid.SelectedObject = null;

        private void btnUpdate_Click(object sender, EventArgs e)
            btnUpdate.Enabled = false;
            objectPropGrid.SelectedObject = null;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Romania Romania
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180321.1 | Last Updated 14 May 2009
Article Copyright 2009 by flavius.stoichescu
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid