Example #1
0
    private void Create()
    {
        HandleDescriptionFieldForm form = new HandleDescriptionFieldForm(_connectionString);
        DialogResult result             = form.ShowDialog();

        if (result.ToString() == "OK")
        {
            DescriptionField newItem = form.GetValue();

            int insertNewRowAt = 0;

            if (dataGridView1.SelectedRows.Count > 0)
            {
                insertNewRowAt = dataGridView1.SelectedRows[0].Index;
                insertNewRowAt++;
            }

            CreateNewItem(newItem, insertNewRowAt);

            dataGridView1.FirstDisplayedScrollingRowIndex = insertNewRowAt;
            dataGridView1.CurrentCell = dataGridView1["ItemName", insertNewRowAt];
            dataGridView1.Rows[insertNewRowAt].Selected = true;

            ConfigHandler.SaveConfig();
        }

        dataGridView1.Focus();
    }
Example #2
0
    private void Edit()
    {
        List <DescriptionField> newItems = ConfigHandler.DescriptionFields;

        bool   save     = false;
        string newName  = null;
        bool   setImage = false;

        foreach (DescriptionField item in newItems)
        {
            if (dataGridView1.SelectedCells[1].Value.ToString() == item.DisplayText)
            {
                HandleDescriptionFieldForm form = new HandleDescriptionFieldForm(_connectionString);
                form.SetValues(item);
                DialogResult result = form.ShowDialog();

                if (result.ToString() == "OK")
                {
                    DescriptionField newItem = form.GetValue();
                    item.DisplayText       = newItem.DisplayText;
                    item.DatabaseFieldName = newItem.DatabaseFieldName;
                    item.UseForImage       = newItem.UseForImage;
                    item.Information       = newItem.Information;
                    newName = newItem.DisplayText;

                    if (item.UseForImage)
                    {
                        setImage = true;
                    }

                    dataGridView1.SelectedCells[1].Value = newItem.DisplayText;
                    save = true;
                }

                break;
            }
        }

        if (save)
        {
            if (setImage)
            {
                ReloadUseForImage(newName);
            }

            ConfigHandler.DescriptionFields = newItems;
            _anyChanges = true;
            ConfigHandler.SaveConfig();
        }

        dataGridView1.Focus();
    }