private void gvIgraci() { //broj stupca gv.ColumnCount = 2; igr = new List <Igraci>(); DB_connection.OpenConn(); if (get_by_id != 0) { igr = DB_GET.Ekipa_Get_By_Id(get_by_id); //dohvacanje igraca iz iste ekipe } else { igr = DB_GET.Igraci_Get_All(); //dohvacanje igraca } DB_connection.CloseConn(); var collection = new ObservableCollection <Igraci>(igr); //stvaranje kolekcije...preko presentera datasource = new BindingSource(collection, null); //vezanje kolekcije za datasource //postavljanje vidljivih stupaca gv.Columns[0].HeaderText = "Ime"; gv.Columns[0].DataPropertyName = "Ime"; gv.Columns[1].HeaderText = "Prezime"; gv.Columns[1].DataPropertyName = "Prezime"; //lambda funkcija (google it)....za dobivanje igraca kojeg se kliknulo u grid view gv.CellClick += (s, e) => { igrac_id = (Igraci)this.igr[e.RowIndex]; }; gv.DataSource = datasource; //vezanje grid view sa datasource (koji je kolekcija) gv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; //da se popuni prostor gv.AutoResizeColumns(); gv.AllowUserToAddRows = false; //ne dopusta dodavanje novih redova }
private void cmbBrisanjeOdabir_SelectedIndexChanged(object sender, EventArgs e) { int selected_idex = cmbBrisanjeOdabir.SelectedIndex; selected_item = cmbBrisanjeOdabir.SelectedItem.ToString(); try { DB_connection.OpenConn(); switch (selected_idex) { case 0: { ekipe = DB_GET.Ekipa_Get_All(); var collection = new ObservableCollection <Ekipa>(ekipe); datasource = new BindingSource(collection, null); selected_item = "EKIPA"; break; } case 1: { igrac = DB_GET.Igraci_Get_All(); var collection = new ObservableCollection <Igraci>(igrac); datasource = new BindingSource(collection, null); selected_item = "IGRAC"; break; } case 2: { prisutan = DB_GET.Prisutnost_Get_All(); var collection = new ObservableCollection <Prisutnost>(prisutan); datasource = new BindingSource(collection, null); selected_item = "PRISUTNOST"; break; } case 3: { trening = DB_GET.Trening_Get_All(); var collection = new ObservableCollection <Trening>(trening); datasource = new BindingSource(collection, null); selected_item = "TRENING"; break; } case 4: { statistike = DB_GET.Statistika_Get_All(); var collection = new ObservableCollection <Statistika>(statistike); datasource = new BindingSource(collection, null); selected_item = "STATISTIKA"; break; } case 5: { zapisnik = DB_GET.Zapisnik_Get_All(); var collection = new ObservableCollection <Zapisnik>(zapisnik); datasource = new BindingSource(collection, null); selected_item = "ZAPISNIK"; break; } case 6: { vjezba = DB_GET.Vjezbe_Get_All(); var collection = new ObservableCollection <Vjezbe>(vjezba); datasource = new BindingSource(collection, null); selected_item = "VJEZBE"; break; } case 7: { kosevi = DB_GET.Kosevi_Get_All(); var collection = new ObservableCollection <Kosevi>(kosevi); datasource = new BindingSource(collection, null); selected_item = "KOSEVI"; break; } } DB_connection.CloseConn(); } catch (ArgumentException err) { lblBrisanjeResult.ForeColor = Color.Red; Change_label("Greška kod brisanja: " + err.ToString()); } dgvBrisanje.DataSource = datasource; dgvBrisanje.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgvBrisanje.AutoResizeColumns(); }