locked
ListView with Inputfield RRS feed

  • Question

  • Hi!

    I habe an Listview that works fine for display fields.

    Now I will have a TextInput in one of the fields.

    herer is the xaml code:

    <Window x:Class="MeinListView.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            DataContext="{Binding RelativeSource={RelativeSource Self}}"
            Title="Suche" Height="515" Width="455" Name="WinAuswahlSuche" Closed="WinAuswahlSuche_Closed">
    
        <Canvas Background="#4B08297E" OpacityMask="#FF08297E" Height="475">
            <ListView Canvas.Left="10" Canvas.Top="10" Height="418" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Fragen}" Name="ListViewMenue3" Width="411" SelectionChanged="ListViewMenue3_SelectionChanged">
                <ListView.View>
                    <GridView AllowsColumnReorder="True">
                        <GridViewColumn DisplayMemberBinding="{Binding Frage}" Header="" Width="200" />
                        <GridViewColumn DisplayMemberBinding="{Binding Antworte}" Header="" Width="200"  InputMethod.IsInputMethodEnabled="True" />
                    </GridView>
                </ListView.View>
            </ListView>
        </Canvas>
    </Window>
    
    

    Best regards

    Bernd

    Thursday, September 29, 2011 3:20 PM

Answers

  • Hi Bernd,

    Please see the code snippet below for ur query.

    XAML:
    
    
    <Window x:Class="SandBox.Window34"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window34" Height="300" Width="300">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="50"></RowDefinition>
            </Grid.RowDefinitions>
            <ListView Grid.Row="0" x:Name="listview">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path = Id}"></GridViewColumn>
                        <GridViewColumn Header="Name">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBox Width="150" Text="{Binding Path = Name, Mode = TwoWay}"></TextBox>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            <ListView Grid.Row="1" x:Name="listviewFetched">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path = Id}"></GridViewColumn>
                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path = Name}">
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            <Button x:Name="btn" Content="Fetch List" Width="200" Height="25" Grid.Row="2" Click="btn_Click"></Button>
        </Grid>
    </Window>
    
    
    CodeBehind:
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    
    namespace SandBox
    {
        /// <summary>
        /// Interaction logic for Window34.xaml
        /// </summary>
        public partial class Window34 : Window
        {
            public List<ListViewBindedClass> MyCollection = new List<ListViewBindedClass>();
            public Window34()
            {
                InitializeComponent();
                MyCollection.Add(new ListViewBindedClass(1, string.Empty));
                MyCollection.Add(new ListViewBindedClass(2, string.Empty));
                MyCollection.Add(new ListViewBindedClass(3, string.Empty));
                listview.ItemsSource = MyCollection;
            }
    
            private void btn_Click(object sender, RoutedEventArgs e)
            {
                listviewFetched.ItemsSource = MyCollection;
            }
        }
    
        public class ListViewBindedClass
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public ListViewBindedClass(int Id, string Name)
            {
                this.Id = Id;
                this.Name = Name;
            }
        }
    }
    


    U can enter ur value in the input field in the first ListView and upon clicking on the "Fetch List" button u will find ur values updated in ur Bounded collection which are then displayed in second ListView.

    Please mark it as an answer if it resolves ur query.


    Regards, Parth Shah
    • Proposed as answer by parth.shah Thursday, September 29, 2011 4:20 PM
    • Marked as answer by Bernd Riemke Thursday, September 29, 2011 5:09 PM
    Thursday, September 29, 2011 4:20 PM

All replies

  • Thursday, September 29, 2011 4:03 PM
  • Hi Bernd,

    Please see the code snippet below for ur query.

    XAML:
    
    
    <Window x:Class="SandBox.Window34"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window34" Height="300" Width="300">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="50"></RowDefinition>
            </Grid.RowDefinitions>
            <ListView Grid.Row="0" x:Name="listview">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path = Id}"></GridViewColumn>
                        <GridViewColumn Header="Name">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBox Width="150" Text="{Binding Path = Name, Mode = TwoWay}"></TextBox>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            <ListView Grid.Row="1" x:Name="listviewFetched">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path = Id}"></GridViewColumn>
                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path = Name}">
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            <Button x:Name="btn" Content="Fetch List" Width="200" Height="25" Grid.Row="2" Click="btn_Click"></Button>
        </Grid>
    </Window>
    
    
    CodeBehind:
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    
    namespace SandBox
    {
        /// <summary>
        /// Interaction logic for Window34.xaml
        /// </summary>
        public partial class Window34 : Window
        {
            public List<ListViewBindedClass> MyCollection = new List<ListViewBindedClass>();
            public Window34()
            {
                InitializeComponent();
                MyCollection.Add(new ListViewBindedClass(1, string.Empty));
                MyCollection.Add(new ListViewBindedClass(2, string.Empty));
                MyCollection.Add(new ListViewBindedClass(3, string.Empty));
                listview.ItemsSource = MyCollection;
            }
    
            private void btn_Click(object sender, RoutedEventArgs e)
            {
                listviewFetched.ItemsSource = MyCollection;
            }
        }
    
        public class ListViewBindedClass
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public ListViewBindedClass(int Id, string Name)
            {
                this.Id = Id;
                this.Name = Name;
            }
        }
    }
    


    U can enter ur value in the input field in the first ListView and upon clicking on the "Fetch List" button u will find ur values updated in ur Bounded collection which are then displayed in second ListView.

    Please mark it as an answer if it resolves ur query.


    Regards, Parth Shah
    • Proposed as answer by parth.shah Thursday, September 29, 2011 4:20 PM
    • Marked as answer by Bernd Riemke Thursday, September 29, 2011 5:09 PM
    Thursday, September 29, 2011 4:20 PM
  • Hi Bernd,

    Please see the code snippet below for ur query.

     

    XAML:
    
    
    
    
    
    <Window x:Class="SandBox.Window34"
    
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
        Title="Window34" Height="300" Width="300">
    
        <Grid>
    
            <Grid.RowDefinitions>
    
                <RowDefinition Height="*"></RowDefinition>
    
                <RowDefinition Height="*"></RowDefinition>
    
                <RowDefinition Height="50"></RowDefinition>
    
            </Grid.RowDefinitions>
    
            <ListView Grid.Row="0" x:Name="listview">
    
                <ListView.View>
    
                    <GridView>
    
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path = Id}"></GridViewColumn>
    
                        <GridViewColumn Header="Name">
    
                            <GridViewColumn.CellTemplate>
    
                                <DataTemplate>
    
                                    <TextBox Width="150" Text="{Binding Path = Name, Mode = TwoWay}"></TextBox>
    
                                </DataTemplate>
    
                            </GridViewColumn.CellTemplate>
    
                        </GridViewColumn>
    
                    </GridView>
    
                </ListView.View>
    
            </ListView>
    
            <ListView Grid.Row="1" x:Name="listviewFetched">
    
                <ListView.View>
    
                    <GridView>
    
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path = Id}"></GridViewColumn>
    
                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path = Name}">
    
                        </GridViewColumn>
    
                    </GridView>
    
                </ListView.View>
    
            </ListView>
    
            <Button x:Name="btn" Content="Fetch List" Width="200" Height="25" Grid.Row="2" Click="btn_Click"></Button>
    
        </Grid>
    
    </Window>
    
    
    
    
    
    CodeBehind:
    
    
    
    
    
    using System;
    
    using System.Collections.Generic;
    
    using System.Linq;
    
    using System.Text;
    
    using System.Windows;
    
    using System.Windows.Controls;
    
    using System.Windows.Data;
    
    using System.Windows.Documents;
    
    using System.Windows.Input;
    
    using System.Windows.Media;
    
    using System.Windows.Media.Imaging;
    
    using System.Windows.Shapes;
    
    
    
    namespace SandBox
    
    {
    
        /// <summary>
    
        /// Interaction logic for Window34.xaml
    
        /// </summary>
    
        public partial class Window34 : Window
    
        {
    
            public List<ListViewBindedClass> MyCollection = new List<ListViewBindedClass>();
    
            public Window34()
    
            {
    
                InitializeComponent();
    
                MyCollection.Add(new ListViewBindedClass(1, string.Empty));
    
                MyCollection.Add(new ListViewBindedClass(2, string.Empty));
    
                MyCollection.Add(new ListViewBindedClass(3, string.Empty));
    
                listview.ItemsSource = MyCollection;
    
            }
    
    
    
            private void btn_Click(object sender, RoutedEventArgs e)
    
            {
    
                listviewFetched.ItemsSource = MyCollection;
    
            }
    
        }
    
    
    
        public class ListViewBindedClass
    
        {
    
            public int Id { get; set; }
    
            public string Name { get; set; }
    
            public ListViewBindedClass(int Id, string Name)
    
            {
    
                this.Id = Id;
    
                this.Name = Name;
    
            }
    
        }
    
    }
    
    

     


    U can enter ur value in the input field in the first ListView and upon clicking on the "Fetch List" button u will find ur values updated in ur Bounded collection which are then displayed in second ListView.

    Please mark it as an answer if it resolves ur query.


    Regards, Parth Shah


    Thats what I search for!!!

    Many Thanks!

    Best Regards

    Bernd

     

    Thursday, September 29, 2011 5:09 PM