Create a ListView control that uses a GridView view mode to display the contents of an ObservableCollection<(Of <(T>)>). : ListView « Windows Presentation Foundation « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » ListViewScreenshots 
Create a ListView control that uses a GridView view mode to display the contents of an ObservableCollection<(Of <(T>)>).
Create a ListView control that uses a GridView view mode to display the contents of an ObservableCollection<(Of <(T>)>).
     


<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Loaded="OnLoad" xmlns:ds="clr-namespace:WpfApplication1">
 
  <Window.Resources>
    <ObjectDataProvider x:Key="EmployeeInfoDataSource" ObjectType="{x:Type ds:myEmployees}"/>
  </Window.Resources>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="50"/>
      <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <TextBlock Grid.Row="0" Grid.Column="0" FontSize="14" HorizontalAlignment="Center">
      ListView created with XAML
    </TextBlock>
    <StackPanel Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center">
      <ListView ItemsSource="{Binding Source={StaticResource EmployeeInfoDataSource}}">
        <ListView.View>
          <GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Employee Information">
            <GridViewColumn DisplayMemberBinding= "{Binding Path=FirstName}" Header="First Name" Width="100"/>
            <GridViewColumn DisplayMemberBinding="{Binding Path=EmployeeNumber}" Header="Employee No." Width="100"/>
          </GridView>
        </ListView.View>
      </ListView>
    </StackPanel>
    <StackPanel Grid.Row="1" Grid.Column="1"  Name="myStackPanel" HorizontalAlignment="Center">
    </StackPanel>
  </Grid>
</Window>
//File:Window.xaml.vb

Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes
Imports System.Collections.ObjectModel


Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window
    Private Sub OnLoad(sender As Object, e As RoutedEventArgs)
      Dim myListView As New ListView()

      Dim myGridView As New GridView()
      myGridView.AllowsColumnReorder = True
      myGridView.ColumnHeaderToolTip = "Employee Information"

      Dim gvc1 As New GridViewColumn()
      gvc1.DisplayMemberBinding = New Binding("FirstName")
      gvc1.Header = "FirstName"
      gvc1.Width = 100
      myGridView.Columns.Add(gvc1)

      Dim gvc3 As New GridViewColumn()
      gvc3.DisplayMemberBinding = New Binding("EmployeeNumber")
      gvc3.Header = "Employee No."
      gvc3.Width = 100
      myGridView.Columns.Add(gvc3)

      myListView.ItemsSource = New myEmployees()
      myListView.View = myGridView
      myStackPanel.Children.Add(myListView)
    End Sub
  End Class

  Public Class EmployeeInfo
    Private _firstName As String
    Private _employeeNumber As String

    Public Property FirstName() As String
      Get
        Return _firstName
      End Get
      Set
        _firstName = value
      End Set
    End Property
    Public Property EmployeeNumber() As String
      Get
        Return _employeeNumber
      End Get
      Set
        _employeeNumber = value
      End Set
    End Property

    Public Sub New(firstname As String, empnumber As String)
      _firstName = firstname
      _employeeNumber = empnumber
    End Sub
  End Class
  Public Class myEmployees
    Inherits ObservableCollection(Of EmployeeInfo)
    Public Sub New()
      Add(New EmployeeInfo("A""1"))
      Add(New EmployeeInfo("B""9"))
      Add(New EmployeeInfo("C""2"))
      Add(New EmployeeInfo("D""4"))
    End Sub
  End Class
End Namespace

   
    
    
    
    
  
Related examples in the same category
1.ListView control with controls for columnsListView control with controls for columns
2.Set Binding ListView.ItemsSourceProperty to ListViewSet Binding ListView.ItemsSourceProperty to ListView
3.Create a ListView control that uses a GridView view mode to display a collection of DateTime objects.Create a ListView control that uses a GridView view mode to display a collection of DateTime objects.
4.Get Bounded item from ListViewGet Bounded item from ListView
5.Create Binding for ListView in codeCreate Binding for ListView in code
6.Use three TextBlocks in one ListViewItemUse three TextBlocks in one ListViewItem
7.Create a ListView control that uses a GridView view mode to display dates.Create a ListView control that uses a GridView view mode to display dates.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.