前提・実現したいこと
WPFで顧客管理システムを作成したいです。
listView内に表示されている言葉を、TexBox上に表示後
編集を行いたいです。
発生している問題・エラーメッセージ
https://tnakamura.hatenablog.com/entry/20080929/1222743177
を参考にさせてもらいながら、多段表示は出来たのですが、
肝心のListVewを選択した際に任意のTextBoxに表示が出来なくて困っています
該当のソースコード
XAML
1 <Grid> 2 <ListView x:Name="listView1" ItemsSource="{Binding}" Margin="0,0,197,0"> 3 <ListView.Resources> 4 5 <!--得意先列ヘッダ用テンプレート--> 6 <DataTemplate x:Key="customerHeaderTemplate"> 7 <StackPanel> 8 <Label Content="得意先コード"/> 9 <Label Content="得意先名"/> 10 </StackPanel> 11 </DataTemplate> 12 13 <!--得意先セル用テンプレート--> 14 <DataTemplate x:Key="customerCellTemplate"> 15 <StackPanel> 16 <Label Content="{Binding Path=CustomerCode}"/> 17 <Label Content="{Binding Path=CustomerName}"/> 18 </StackPanel> 19 </DataTemplate> 20 21 <!--伝票種列ヘッダ用テンプレート--> 22 <DataTemplate x:Key="kindHeaderTemplate"> 23 <StackPanel> 24 <Label Content="伝票種"/> 25 <Label Content="伝票番号フラグ"/> 26 </StackPanel> 27 </DataTemplate> 28 29 <!--伝票種セル用テンプレート--> 30 <DataTemplate x:Key="kindCellTemplate"> 31 <StackPanel> 32 <Label Content="{Binding Path=Kind}"/> 33 <Label Content="{Binding Path=NoFlag}"/> 34 </StackPanel> 35 </DataTemplate> 36 37 </ListView.Resources> 38 <ListView.View> 39 <GridView> 40 <!--列を追加。--> 41 <!--DisplayMemberBinding を使って、列に表示する Slip クラスのプロパティを指定しています--> 42 <GridViewColumn Header="伝票日付" DisplayMemberBinding="{Binding Path=Date}"/> 43 44 <!--伝票種列ヘッダ用のテンプレートと伝票種セル用のテンプレートを指定--> 45 <GridViewColumn HeaderTemplate="{StaticResource kindHeaderTemplate}" CellTemplate="{StaticResource kindCellTemplate}"/> 46 47 <GridViewColumn Header="伝票番号" DisplayMemberBinding="{Binding Path=No}"/> 48 49 <!--得意先列ヘッダ用のテンプレートと得意先セル用のテンプレートを指定--> 50 <GridViewColumn HeaderTemplate="{StaticResource customerHeaderTemplate}" CellTemplate="{StaticResource customerCellTemplate}"/> 51 </GridView> 52 </ListView.View> 53 </ListView> 54 <TextBox HorizontalAlignment="Left" Height="23" Margin="514,94,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/> 55 </Grid>
C#
namespace WpfApp27 { /// 伝票を表すクラス public class Slip { public DateTime Date { get; set; } public int Kind { get; set; } public int NoFlag { get; set; } public long No { get; set; } public string CustomerCode { get; set; } public string CustomerName { get; set; } } public partial class Window1 : Window { public Window1() { InitializeComponent(); // ListView に表示するデータを作成 Slip[] slips = new Slip[]{ new Slip(){Date=DateTime.Today,Kind=1,NoFlag=1,No=1,CustomerCode="0001", CustomerName="田中"}, new Slip(){Date=DateTime.Today,Kind=1,NoFlag=1,No=2,CustomerCode="0002", CustomerName="佐藤"}, new Slip(){Date=DateTime.Today,Kind=1,NoFlag=1,No=3,CustomerCode="0003", CustomerName="高橋"}, new Slip(){Date=DateTime.Today,Kind=1,NoFlag=1,No=4,CustomerCode="0004", CustomerName="加藤"}, new Slip(){Date=DateTime.Today,Kind=1,NoFlag=1,No=5,CustomerCode="0005", CustomerName="山内"} }; // ListView にセットする listView1.DataContext = slips; } } }
試したこと
ネットで検索しましたが結局わからずここで質問させていただきました。
補足情報(FW/ツールのバージョンなど)
Windows10
visual studio 2017
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/05 00:23