Advertisement
VladTheBush

C# ViewList

Apr 15th, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Programiranje_domaci_3 {
  12.     public partial class Form1 : Form {
  13.         List<Knjiga> listKnjiga = new List<Knjiga>();
  14.  
  15.         public Form1() {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void popuni() {
  20.             Knjiga k = new Knjiga();
  21.  
  22.             k.Naziv = textBox1.Text;
  23.             k.ImeAutora = textBox2.Text;
  24.             k.Izdavac = comboBox1.SelectedItem.ToString();
  25.             k.GodIzd = textBox3.Text;
  26.             listKnjiga.Add(k);
  27.         }
  28.         private void button1_Click(object sender, EventArgs e) {
  29.             popuni();
  30.             textBox1.Clear();
  31.             textBox2.Clear();
  32.             comboBox1.SelectedIndex = -1;
  33.             textBox3.Clear();
  34.             textBox1.Focus();
  35.         }
  36.  
  37.         private void button2_Click(object sender, EventArgs e) {
  38.             if(!listView1.Visible) {
  39.                 foreach(Knjiga k in listKnjiga) {
  40.                     string[] s = new string[] { k.Naziv, k.ImeAutora, k.Izdavac, k.GodIzd };
  41.                     ListViewItem red = new ListViewItem(s);
  42.                     red.Tag = k;
  43.                     listView1.Items.Add(red);
  44.                 }
  45.                 listView1.Visible = true;
  46.             }
  47.             else
  48.                 listView1.Visible = false;
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement