5,548,129 members and growing! (20,902 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate

Customized ListView Control

By kennedy_franklin

This is a customized ListView control having facility for sorting, finding an element in the list, selecting necessary rows from the list by using a checkbox, selecting all rows in the list and inverting the selection.
VB, Windows, .NET 1.0, .NETVisual Studio, VS.NET2002, Dev

Posted: 25 Feb 2005
Updated: 25 Feb 2005
Views: 92,541
Bookmarked: 27 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
13 votes for this Article.
Popularity: 3.62 Rating: 3.25 out of 5
5 votes, 38.5%
1
0 votes, 0.0%
2
1 vote, 7.7%
3
3 votes, 23.1%
4
4 votes, 30.8%
5

Introduction

This is a customized ListView control having facility for sorting, finding an element in the list, selecting necessary rows from the list by using a checkbox, selecting all rows in the list and inverting the selection.

And also, this control has the provision to fetch data from three different types of data sources (Jet, Oracle & SQL Server) just by specifying the following necessary inputs. Given below are the Connection properties in the control. In the Property window, these will be shows in the Category called “Connection”.

  • DataSource

    This property is used to specify the data source for the connection.

  • Password

    This property is used to specify the password for the database to open it in the connection.

  • Provider

    This property informs the connection about the type of database (Jet/Oracle/SQL Server) from which we are going to fetch the data to the control.

  • UserId

    This property is used to specify the UserId for the database to the open the connection.

Given below are the other ListView properties in the control. In the Property window, these will be shown in the Category called “Listview Settings”.

  • Checkboxes

    This will tell the control whether we need the checkbox in the ListView or not.

  • EasyMultiSelect

    This will tell the control whether to display the selected item in the bottom or not.

  • EasySelect

    This will tell the control whether we need the “Select All” and “Invert” buttons or not.

  • FieldDescriptionList

    Used to specify the column name for the ListView columns.

  • FieldNameList

    Used to specify the database column from which data is to be displayed in columns in the ListView.

  • FieldSizeList

    Used to specify the column size for the ListView columns.

  • FullRowSelect

    Turn On/Off the FullRowSelection in the ListView.

  • GridLines

    Turn On/Off the GridLines in the ListView.

  • QueryName

    Specify the SQL statement to be used to fetch data from the database to the ListView.

In the ListView control, there are two non-browsable properties:

  • SelectedItems

    This will return the list of items selected from the ListView.

  • SelectedRows

    This is a ReadOnly property that will return the deleted rows as a DataSet.

Technical part of this control

  • When we load the user defined control in the toolbox, it will have the ListView control icon instead of the default icon.
  • Grouping the properties under certain categories in the Property window.
  • Description for each and every property.

The above mentioned things are established in the control using the “System.ComponentModel”, by using the following attributes:

  • <ToolboxBitmap>

    This attribute is used to specify the icon for the user control.

  • <Description>

    This attribute is used to specify a short description about a property.

  • <Category>

    This attribute is used to place a property in the desired category.

E.g.:

<ToolboxBitmap(GetType(ListView))> _
Public Class ListSelected
<Description("On/Off the Checkbox in Listview"), Category("Listview Settings")> _
    Public Property Checkboxes() As Boolean
        Get
            Checkboxes = LstView.CheckBoxes
        End Get
        Set(ByVal New_Checkboxes As Boolean)
            LstView.CheckBoxes = New_Checkboxes
        End Set
    End Class

Sorting

Custom class (LstSort) implements the IComparable interface and overrides the Compare function with its own code. Take that class and set the ListViewItemSorter property of the ListView equal to it.

Have a look at how it is used in the column click event of the ListView object. Given below is the screenshot of the Design Time Property Sheet of the custom ListView:

How to use the control

Re-build the control and load this control in your own project. Set the properties as in the property sheet in the above screen shot, and then run the application.

The test application screenshot is as follows. I just placed the control and set the properties as mentioned above.

If we click on the “Selected Items” button, the screen will look like this:

If we click on the “Selected Rows” button, the screen will look like this:

If we press the ‘OK’ button, it will show the next selected row in the message box.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

kennedy_franklin


I am J. Franklin Kennedy, Working as a programmer in application software developement.


Occupation: Web Developer
Location: Kuwait Kuwait

Other popular C / C++ Language articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralGood Control!memberLucky_Lu9917:17 3 Jul '08  
Generalexcellentmembergoodyboy5:24 25 Jun '08  
GeneralSorry but this is quite poormemberalsdanm10:43 8 Oct '07  
GeneralTo add a check bok in listviewmember2:42 18 Jan '07  
QuestionGet ting rid of the extra column on the rightmemberrb987:44 30 Aug '06  
AnswerRe: Get ting rid of the extra column on the rightmemberAcidRaZor22:35 11 Oct '06  
GeneralHide ColumnmemberVitoto10:27 6 Jul '05  
GeneralRe: Hide ColumnmemberAcidRaZor22:38 11 Oct '06  
GeneralAddition of a search for the file. ?memberclaudetom013:46 7 Mar '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Feb 2005
Editor: Smitha Vijayan
Copyright 2005 by kennedy_franklin
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project