public virtual void Edit() { if (SelectedItem == null) { return; } int index = dataGridViewUserControl1.getSelectedItemIndex(); try { EntityDetailForm form = createEntityDetailForm(getEntityId(SelectedItem)); if (form.ShowDialog() == DialogResult.OK) { T entity = (T)form.Entity; List <T> items = dataGridViewUserControl1.getItems <T>(); items[index] = entity; dataGridViewUserControl1.setItems <T>(items); // ovo ponovo sortira items dataGridViewUserControl1.setSelectedItem <T>(entity); } } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } }
protected virtual void AddNew() { try { EntityDetailForm form = createEntityDetailForm(null); if (form.ShowDialog() == DialogResult.OK) { T newEntity = (T)form.Entity; List <T> items = dataGridViewUserControl1.getItems <T>(); items.Add(newEntity); dataGridViewUserControl1.setItems <T>(items); dataGridViewUserControl1.setSelectedItem <T>(newEntity); updateEntityCount(); } } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } }