Floating FB sharing byReview Results

Floating FB sharing byReview Results

  • WPF Tutorial

    • # Read in Your Language

    WPF Controls

    Tutorial Home | Layouts | Containers| Button | CheckBox and CheckedListBox | ComboBox| DateTimePicker and MonthCalendar | DataGrid | Label and LinkLabel| ListBox | ListView | TextBox and MaskedTextBox| PictureBox and ProgressBar | TreeView | WebBrowser| Menus,Status and Toolbar | RadioButton | RichTextBox| ToolTip and Scrolling | Custom Controls

    ListView control in WPF


    Namespace : System.Windows.Controls.ListView

    Designer Code:

         <ListView Name="lst1" SelectionChanged="lst1_SelectionChanged">

    Code Behind:

            // Window1.xaml.cs
    private void lst1_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListViewItem lstval = (ListViewItem)lst1.SelectedItem; }

    VirtualMode is supported by default when the ItemsPanel=VirtualizedItemsPanel.

    Without specifying a something special in the “View” the ListView looks just like a ListBox.
    for view like LargeIcon, SmallIcon, Details use the View property to specify how you want the control to layout.

    Designer Code:

                <GridViewColumn Header="Name" 
                DisplayMemberBinding="{Binding Path=Name}"/>
                <GridViewColumn Header="Value" 
                DisplayMemberBinding="{Binding Path=Value}"/> 

    Code Behind:

           // Data.cs
    public class SampeData { public string Name { get; set; } public string Value { get; set; } } //DataBinding SampeData data = getDataItem(index); this.LstView1.Items.Add(data);

    Sample - Building up details view

    Column headers in the ListView are specified in the ListView.View, which is set to be a GridView.

        <XmlDataProvider x:Key="EmployeeData" XPath="/EmployeeData">
          <EmployeeData xmlns="">
        <ListView ItemsSource="{Binding Source={StaticResource EmployeeData}, 
              <GridViewColumn Header="First Name" 
                              DisplayMemberBinding="{Binding XPath=FirstName}" />
              <GridViewColumn Header="Last Name" 
                              DisplayMemberBinding="{Binding XPath=LastName}" />

    DataBinding From Database in Listview:

                //Create the ListView
                ListView listview = new ListView();
                //Create the GridView and create GridViewColumns
                GridView gridview = new GridView();
                GridViewColumn gvcolumn = new GridViewColumn();
                gvcolumn.Header = "FirstName";
                gvcolumn.DisplayMemberBinding = new Binding("FirstName");
                gvcolumn = new GridViewColumn();
                gvcolumn.Header = "LastName";
                gvcolumn.DisplayMemberBinding = new Binding("LastName");
                //Set the ListView's View to GridView
                listview.View = gridview;
                //Set the DataContext property of the ListView to 
                //the DataTable and bind the ItemsSourceProperty to {Binding}
                Binding bind = new Binding();
                //Use this (Or)
                listview.DataContext = table;
                listview.SetBinding(ListView.ItemsSourceProperty, bind);
                //Set the content of the Window to the ListView
                Content = listview;
                //alternate code 
                listview.DataContext = ds.Tables[0].DefaultView;

    Checkboxes in Listview:

            <GridViewColumn Header="Balance" Width="140">
                    <CheckBox Tag="{Binding}" Name="Complete" 
                    IsThreeState="False" Checked="onButtonClick" />

    << Previous >> | << Next >>