Exemple #1
0
        private void ChangeImage(int rowIndex, string fileName, bool multiEdit)
        {
            try
            {
                var image = Image.FromFile(fileName);

                if (!multiEdit)
                {
                    var oldImage = (Image)itemGrid.Rows[rowIndex].Cells[ICONINDEX].Value;
                    if (oldImage != null)
                    {
                        ImagesToDispose.Add(oldImage);
                    }

                    ItemList[rowIndex].SetIcon(image);
                    itemGrid.NotifyCurrentCellDirty(true);
                }
                else
                {
                    foreach (DataGridViewCell cell in itemGrid.SelectedCells)
                    {
                        if (cell.ColumnIndex != ICONINDEX)
                        {
                            continue;
                        }

                        var oldImage = (Image)cell.Value;
                        if (oldImage != null)
                        {
                            ImagesToDispose.Add(oldImage);
                        }

                        ItemList[cell.RowIndex].SetIcon((Image)image.Clone());
                        itemGrid.UpdateCellValue(ICONINDEX, cell.RowIndex);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show("Could not load image!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        private void btn_removeItem_Click(object sender, EventArgs e)
        {
            foreach (var selectedObject in itemGrid.SelectedCells)
            {
                var selectedCell  = (DataGridViewCell)selectedObject;
                var selectedIndex = selectedCell.RowIndex;

                if (ItemList.Count <= 1 || selectedIndex >= ItemList.Count || selectedIndex < 0)
                {
                    continue;
                }
                if (selectedIndex == ItemList.Count - 1 && selectedIndex == itemGrid.CurrentRow.Index)
                {
                    itemGrid.ClearSelection();
                    itemGrid.CurrentCell          = itemGrid.Rows[itemGrid.CurrentRow.Index - 1].Cells[itemGrid.CurrentCell.ColumnIndex];
                    itemGrid.CurrentCell.Selected = true;
                }
                if (ItemList[selectedIndex].Icon != null)
                {
                    ImagesToDispose.Add(ItemList[selectedIndex].Icon);
                }
                ItemList.RemoveAt(selectedIndex);
            }
        }