Exemplo n.º 1
0
        private void editContact_Click(object sender, EventArgs e)
        {
            try
            {
                if (ContactsTable.GetCellCount(DataGridViewElementStates.Selected) > 1 == false &&
                    !string.IsNullOrWhiteSpace(ContactsTable.CurrentCell.Value.ToString()) &&
                    ContactsTable.SelectedCells.Count != 0)
                {
                    actualValue = ContactsTable.CurrentCell.Value.ToString();

                    checkStatus = false;

                    for (int i = 0; i < ContactsTable.GetCellCount(DataGridViewElementStates.Selected); i++)
                    {
                        EditRowIndex = ContactsTable.SelectedCells[i].RowIndex;

                        EditColumnIndex = ContactsTable.SelectedCells[i].ColumnIndex;
                    }

                    List <string> wholeValues = new List <string>();

                    List <string> oldValues = new List <string>();

                    wholeValues.Clear();

                    oldValues.Clear();

                    string readyRow = null;

                    for (int i = 0; i < ContactsTable.GetCellCount(DataGridViewElementStates.Selected); i++)
                    {
                        int rowIndex = ContactsTable.SelectedCells[i].RowIndex;

                        for (int j = 0; j < 8; j++)
                        {
                            readyRow += ContactsTable.Rows[rowIndex].Cells[j].Value.ToString() + "|";
                        }

                        wholeValues.Add(readyRow);

                        readyRow = null;
                    }

                    EditContact Window = new EditContact();

                    DialogResult Check = Window.ShowDialog();

                    try
                    {
                        if (checkStatus == false)
                        {
                            ContactsTable.CurrentCell.Value = EditContact.readyValue;

                            #region Pobieranie aktualnej wersji tabeli

                            int contactCount = ContactsTable.Rows.Count;

                            string ReadyContact = null;

                            for (int i = 0; i < contactCount - 1; i++)
                            {
                                ReadyContact = null;

                                for (int j = 0; j < 8; j++)
                                {
                                    ReadyContact += ContactsTable.Rows[i].Cells[j].Value.ToString() + "|";
                                }

                                oldValues.Add(ReadyContact);
                            }

                            #endregion

                            for (int i = 0; i < oldValues.Count; i++)
                            {
                                for (int j = 0; j < copyOfContacts.Count; j++)
                                {
                                    if (copyOfContacts[j].Trim() == wholeValues[0].Trim())
                                    {
                                        for (int k = 0; k < oldValues.Count; k++)
                                        {
                                            copyOfContacts[j] = oldValues[EditRowIndex];
                                        }
                                    }
                                }
                            }
                        }
                    }

                    catch
                    {
                    }
                }

                else
                {
                    Navigate.ToolTipTitle = "Informacja";

                    Navigate.ToolTipIcon = ToolTipIcon.Warning;

                    Navigate.Show("Zaznacz jedną komórkę w tabeli!", backgroundTip, 5, backgroundTip.Height - 5, 2500);
                }
            }

            catch
            {
                //błąd edytowania komórek
            }
        }