728x90
반응형
ListView 추가/삭제 ( add / remove / delete / del ) |
[MainWindow.xaml]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" xmlns:Properties="clr-namespace:WpfApp1.Properties" x:Class="WpfApp1.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="521.5" Width="572.968"> <Grid Margin="10"> <ListView x:Name="ListView01" HorizontalAlignment="Left" Width="448" Height="461" VerticalAlignment="Top" Margin="87,0,0,0"> <ListView.View> <GridView> <GridViewColumn Header="Name" Width="200" DisplayMemberBinding="{Binding Name}" /> <GridViewColumn Header="Age" Width="100" DisplayMemberBinding="{Binding Age}" /> </GridView> </ListView.View> </ListView> <Button x:Name="btnADD" Content="ADD" HorizontalAlignment="Left" VerticalAlignment="Top" Width="82" Height="41" Click="btnADD_Click"/> <Button x:Name="btn_DEL" Content="DEL" HorizontalAlignment="Left" Height="41" Margin="0,46,0,0" VerticalAlignment="Top" Width="82" Click="btn_DEL_Click"/> </Grid> </Window> | cs |
[MainWindow.xaml.cs]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | using System.Collections.Generic; using System.Windows; namespace WpfApp1 { /// <summary> /// MainWindow.xaml에 대한 상호 작용 논리 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } List<Man> items = new List<Man>(); public class Man { public string Name { get; set; } public int Age { get; set; } } private void btnADD_Click(object sender, RoutedEventArgs e) { items.Add(new Man() { Name = "aaa", Age = 555 }); items.Add(new Man() { Name = "bbb", Age = 444 }); items.Add(new Man() { Name = "ccc", Age = 333 }); items.Add(new Man() { Name = "ddd", Age = 222 }); items.Add(new Man() { Name = "eee", Age = 111 }); ListView01.ItemsSource = items; ListView01.Items.Refresh(); } private void btn_DEL_Click(object sender, RoutedEventArgs e) { foreach (Man item in ListView01.SelectedItems) { items.Remove(item); } ListView01.Items.Refresh(); } } } | cs |
728x90
반응형
'Programing (프로그래밍) > WPF & C# (C Sharp)' 카테고리의 다른 글
WPF & C# - 형변환 ( convert / conv / int / double / string ) (0) | 2018.04.20 |
---|---|
WPF & C#- XML 파일리스트 저장 ( ListView ) (0) | 2018.04.18 |
WPF & C# - ini 쓰기, 다양하게 읽기 ( config / setup / Dictionary ) (2) | 2018.04.17 |
WPF & C# - 로그파일 만들기 ( LOG ) (0) | 2018.04.13 |
어셈블리 정보 값과 파일 속성 값 (0) | 2018.01.16 |
WPF & C# - 하이퍼링크 ( Hyperlink) (4) | 2018.01.11 |
WPF & C# - 이미지 넣기 ( image / img / BitmapImage / Uri / pack / ico / riKind.Relative / Uniform / None / UniformToFill / Fill / 가로세로비율 ) (2) | 2018.01.10 |
XML 파싱 - XPATH ( parsing / 기상청 / weather / 날씨 ) (0) | 2018.01.10 |