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 Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Windows Presentation Foundation » ListView 
16.32.6.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
WPF Create A List View Control That Uses A Grid View View Mode To Display The Contents Of An Observable Collection Of T
16.32.ListView
16.32.1.ListView control with controls for columnsListView control with controls for columns
16.32.2.Set Binding ListView.ItemsSourceProperty to ListViewSet Binding ListView.ItemsSourceProperty to ListView
16.32.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.
16.32.4.Get Bounded item from ListViewGet Bounded item from ListView
16.32.5.Create Binding for ListView in codeCreate Binding for ListView in code
16.32.6.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>)>).
16.32.7.Use three TextBlocks in one ListViewItemUse three TextBlocks in one ListViewItem
16.32.8.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.
16.32.9.ListView using GridView.HeaderTemplate and GridViewColumn.CellTemplate propertiesListView using GridView.HeaderTemplate and GridViewColumn.CellTemplate properties
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.