110 likes | 146 Views
CIS 338: ListView Control. Dr. Ralph D. Westfall May, 2011. ListView Control. used in Windows Explorer to view files try File>Open>Browse in IE can display data in variety of ways large or small icons displayed horizontally single or multiple-column lists
E N D
CIS 338: ListView Control Dr. Ralph D. Westfall May, 2011
ListView Control • used in Windows Explorer to view files • try File>Open>Browse in IE • can display data in variety of ways • large or small icons displayed horizontally • single or multiple-column lists • multiple-column lists can be sorted (only by first columns, ascending or descending)
ListView Startup Code Private clmX as ColumnHeader Private itmX As ListViewItem Private Sub [formname]_Load( … etc. 'creating column headers (captions) 1st 'Optional: add ImageLists from ToolBox 'Add icons to ImageList's Images property ListView1.LargeImageList = ImageList1 ListView1.SmallImageList = ImageList2
ListView Headers clmX = ListView1.Columns.Add _ ("[ ]", 90, HorizontalAlignment.Center) clmX = ListView1.Columns.Add _ ("[ ]", 100, HorizontalAlignment.Center) 'repeat code for each additional header ListView1.View = View.Details 'show columns over outputs
ListView Row Data 'loading row of list items itmX = ListView1.Items.Add("[ ]") itmX.SubItems.Add("[ ]") itmX.SubItems.Add("[ ]" itmX.ImageIndex = (#) 'Integer ‘Can repeat for additional SubItems. ‘Can put above lines in a loop in a Sub, 'to load from an array, file or database, 'or just use loop indexes to load a demo. ‘See Notes.
ListView View Mode 'can set/change View property in code ListView1.View = View.Details 'table ListView1.Show() 'see array data example in Notes ListView.Clear() 'removes items, but columns stay there
Microsoft ListView Tutorial(more work than it's worth?) • copy and paste documentation example code into a form with just a button, and then modify it as necessary • download images below into project's \bin subdirectory • image files for use with sample code • see notes below to set code paths
Other ListView Tutorials • Listview«GUI«VB.NET Tutorial • Filling Listview with data retrieved from database
ListView Reversible Sorting Private Sub ListView1_ColumnClick( …notes Static intCounter As Integer 'persists If intCounter Mod 2 = 1 Then 'odd count ListView1.Sorting = SortOrder.Ascending Else 'even count ListView1.Sorting = SortOrder.Descending End If intCounter += 1 End Sub 'notes: another approach 'do NOT set a Sorting value in Properties of ListView control if you use code for sorting
ListView Control Sorting • in VB 6, it was easy to sort by columns • less easy in .NET to sort just 1st column • sorting on other columns is even harder • my opinion is that Microsoft really should provide this as a standard feature rather than requiring additional coding
Getting Data into ListView • Transport.zip code shows different ways of getting data for a ListView • demonstrates use of data coming from a data tier in one of the three ways: • from class objects in an array • from parallel arrays • from concatenated strings