1 / 11

CIS 338: ListView Control

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

gothard
Download Presentation

CIS 338: ListView Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 338: ListView Control Dr. Ralph D. Westfall May, 2011

  2. 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)

  3. 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

  4. 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

  5. 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.

  6. 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

  7. 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

  8. Other ListView Tutorials • Listview«GUI«VB.NET Tutorial • Filling Listview with data retrieved from database

  9. 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

  10. 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

  11. 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

More Related