// ContextMenu Items private void addToolStripMenuItem_Click(object sender, EventArgs e) { // What I can do here is have it createa a new blank vocab object. AddUpdateDialog addDialog = new AddUpdateDialog(); Vocab vocabItem = new Vocab(); addDialog.Text = "Add Vocab"; addDialog.Tag = vocabItem; if (addDialog.ShowDialog(this) == DialogResult.OK) { if (!(string.IsNullOrWhiteSpace(vocabItem.PhraseIn))) { // add VocabList item into List vocabList.Add(new Vocab(vocabItem.PhraseIn, vocabItem.PhraseOut, vocabItem.URL, vocabItem.Tag)); UpdateValues(); UpdateSelection(vocabItem); } } addDialog.Dispose(); }
private void AddUpdateDialog_Load(object sender, EventArgs e) { this.vocab = (Vocab)this.Tag; this.phraseInTxtBox.Text = this.vocab.PhraseIn.ToString(); this.phraseOutTxtBox.Text = this.vocab.PhraseOut.ToString(); if (!(string.IsNullOrWhiteSpace(vocab.URL))) { this.urlCheck.Checked = true; this.pathTxtBox.Text = this.vocab.URL.ToString(); } }
private void UpdateSelection(Vocab vocabItem) { int listIndex; // search for location of itemAdded listIndex = vocabList.IndexOf(vocabList.Where(x => x.PhraseIn == vocabItem.PhraseIn).FirstOrDefault()); dgvVocab.ClearSelection(); dgvVocab.Rows[listIndex].Selected = true; // scroll down to selected dgv dgvVocab.FirstDisplayedScrollingRowIndex = dgvVocab.SelectedRows[0].Index; }