コード例 #1
0
        private bool AddWord()
        {
            List <string> wordsToAdd = new List <string>();

            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (cell.ColumnIndex == 0)
                    {
                        if (!string.IsNullOrEmpty((string)cell.Value))
                        {
                            cell.Value = cell.Value.ToString().Trim();

                            if (string.IsNullOrEmpty((string)cell.Value))
                            {
                                MessageBox.Show(this, "Enter one translation for every language.", "Error",
                                                MessageBoxButtons.OK, MessageBoxIcon.Warning);

                                return(false);
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "Enter one translation for every language.", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);

                            return(false);
                        }


                        wordsToAdd.Add(cell.Value.ToString().ToLower());
                    }
                }
            }

            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cell.Value = null;
                }
            }

            WinFormsHelper.Add(parentFormWordList.CurrentList, wordsToAdd.ToArray());

            parentFormWordList.RefreshLoadedList();

            dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0];
            dataGridView.BeginEdit(true);

            wordAdded = true;

            return(true);
        }