Results 1 to 2 of 2

Thread: Binding Object array to ListView

  1. #1

    Thread Starter
    Addicted Member garyjohn_2000's Avatar
    Join Date
    Apr 2005
    Location
    Timbaland
    Posts
    243

    Binding Object array to ListView

    First of all, this will be my first WPF project (Kinda late, I know -.-). Having done some work with Windows Forms and ASP, thought I would try this out as well. The objective is to make a trendy, better-looking UI for managing Windows Services on a single host machine, much like the old MS Management Console for Windows services on Windows XP.

    So, I am trying to list all installed services in a Listview. (If there is a better way to show the list, please enlighten me.) Getting the list of all installed services is easy with System.ServiceProcess.ServiceController.GetServices() method. It returns an Array of ServiceController objects, each representing one installed Windows service on the host machine.

    But, getting that array onto the ListView is giving me trouble. I have read somewhere that it is advisable to bind the collection directly to the listview. For some reason, I am not being able to make it work as I would like it to.

    Here is the XAML:
    Code:
            <ListView Grid.Column="1" Grid.Row="1" Name="ServicesLVW" ItemsSource="{Binding Services}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding DisplayName}" />
                        <GridViewColumn Header="Status" DisplayMemberBinding="{Binding Path=Status}" />
                        <GridViewColumn Header="Service Type" DisplayMemberBinding="{Binding Path=ServiceType}" />
                    </GridView>
                </ListView.View>
            </ListView>
    Here is the VB Code:
    vb.net Code:
    1. Imports System.ServiceProcess
    2. Imports System.Collections.ObjectModel
    3.  
    4. Partial Public Class Window2
    5.     Public _services() As ServiceController
    6.  
    7.     Public ReadOnly Property Services() As ServiceController()
    8.         Get
    9.             Return _services
    10.         End Get
    11.     End Property
    12.  
    13.     Public Sub New()
    14.         _services = ServiceController.GetServices
    15.  
    16.         ' This call is required by the Windows Form Designer.
    17.         InitializeComponent()
    18.  
    19.         ' Add any initialization after the InitializeComponent() call.
    20.  
    21.     End Sub
    22.  
    23. End Class

    I know there is something wrong, but this being my first project in WPF, I can't seem to put my finger on where or what. Please advise. All and any suggestions will be much appreciated. Thanks in advance


    Anyone who has never made a mistake has never tried anything new. - Einstein
    Peace!

  2. #2

    Thread Starter
    Addicted Member garyjohn_2000's Avatar
    Join Date
    Apr 2005
    Location
    Timbaland
    Posts
    243

    Re: Binding Object array to ListView

    28 views and no response...*crosses fingers* I hope someone would point me in the right direction Q__Q


    Anyone who has never made a mistake has never tried anything new. - Einstein
    Peace!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width