Advertisement
Guest User

przyklad

a guest
Jan 5th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4.  
  5. namespace WykopTest
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         private readonly List<string> firstList;
  10.         private readonly List<string> secondList;
  11.         private int _actualList = 1;
  12.  
  13.         public Form1()
  14.         {
  15.             firstList = new List<string> {"AAAA", "BBBB"};
  16.             secondList = new List<string> {"CCCC", "DDDD"};
  17.             InitializeComponent();
  18.             AddItems(listView1, firstList);
  19.         }
  20.  
  21.         private void AddItems(ListView list, IEnumerable<string> items)
  22.         {
  23.             list.Items.Clear();
  24.             foreach (var item in items)
  25.             {
  26.                 list.Items.Add(item);
  27.             }
  28.         }
  29.  
  30.         private void button1_Click(object sender, EventArgs e)
  31.         {
  32.             if (_actualList == 1)
  33.             {
  34.                 AddItems(listView1, secondList);
  35.                 _actualList = 2;
  36.             }
  37.             else
  38.             {
  39.                 AddItems(listView1, firstList);
  40.                 _actualList = 1;
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement