private void OnAddWord() { MPBDataSet.PhrasebookRow row = DBWrapper.Instance.CreateNewDataRow(); row._language = row._english = SearchTextBox.Text; DBWrapper.RowWithCategoryInfo rwci = new DBWrapper.RowWithCategoryInfo(row); EditForm form = new EditForm(rwci); if (form.ShowDialog() == DialogResult.OK) { bool bAdded = DBWrapper.Instance.InsertRow(rwci); if (bAdded) { dataGridView.DataSource = null; ReadDatabase(); } } }
private void OnEditRow(object sender, EventArgs paramArgs) { if (dataGridView.SelectedRows.Count > 0) { DataGridViewRow selectedDataRow = dataGridView.SelectedRows[0]; MPBDataSet.PhrasebookRow selectedRow = selectedDataRow.DataBoundItem as MPBDataSet.PhrasebookRow; MPBDataSet.PhrasebookRow editedRow = selectedRow; DBWrapper.RowWithCategoryInfo rwci = new DBWrapper.RowWithCategoryInfo(editedRow); EditForm form = new EditForm(rwci); if (form.ShowDialog() == DialogResult.OK) { selectedRow = rwci.Row; DBWrapper.Instance.UpdateRow(rwci); if (SearchTextBox.Text != string.Empty) { UpdateDataGridView(); } } } }
public EditForm(DBWrapper.RowWithCategoryInfo rwci) { InitializeComponent(); // Save the original row m_originalRWCI = rwci; // Clone it to a new row MPBDataSet.PhrasebookRow newRow = DBWrapper.Instance.CreateNewDataRow(); m_editedRWCI = new DBWrapper.RowWithCategoryInfo(newRow); m_editedRWCI.Row.ItemArray = m_originalRWCI.Row.ItemArray; // Set data source and binding phrasebookBindingSource.DataSource = m_editedRWCI.Row; textBoxFinnish1.TxtBox.DataBindings.Add(new Binding("Text", phrasebookBindingSource, "_language")); txtEnglish.DataBindings.Add(new Binding("Text", phrasebookBindingSource, "_english")); foreach (KeyValuePair <string, long> category in DBWrapper.Instance.CategoriesMap) { if (category.Key == "All") { continue; } CheckBox cb = new CheckBox(); cb.Text = category.Key; if (rwci.CatID2CheckboxMap.ContainsKey(category.Value)) { cb.Checked = true; } cb.AutoSize = true; flowLayoutPanel1.Controls.Add(cb); } }