コード例 #1
0
ファイル: ListPanel.cs プロジェクト: fossabot/ManagedIrbis
        public ListPanel
        (
            MainForm mainForm
        )
            : base(mainForm)
        {
            InitializeComponent();

            ExemplarList = new BindingList <ExemplarInfo>();

            if (!ReferenceEquals(mainForm, null))
            {
                mainForm.Icon = Properties.Resources.Document;
            }

            _bindingSource.DataSource = ExemplarList;

            Controller.Controls.AddRange
            (
                new Control[]
            {
                _addButton, _buildButton,
                _clearButton, _deleteButton,
                _numberBox
            }
            );
            Controller.DisableControls();

            JObject config = JsonUtility.ReadObjectFromFile("config.json");

            DataColumnInfo[] columns = config.SelectToken("grid")
                                       .ToObject <DataColumnInfo[]>();
            DataGridViewUtility.ApplyColumns(_grid, columns);

            ListFormat[] formats = config.SelectToken("format")
                                   .ToObject <ListFormat[]>();
            _formatBox.DataSource    = formats;
            _formatBox.DisplayMember = "Description";

            ListSort[] sort = config.SelectToken("sort")
                              .ToObject <ListSort[]>();
            _sortBox.DataSource    = sort;
            _sortBox.DisplayMember = "Description";

            ListVariant[] variants = config.SelectToken("list")
                                     .ToObject <ListVariant[]>();
            _variantBox.DataSource    = variants;
            _variantBox.DisplayMember = "Title";

            _header = config.SelectToken("header")
                      .ToObject <MoonExcelData[]>();
            _footer = config.SelectToken("footer")
                      .ToObject <MoonExcelData[]>();
        }
コード例 #2
0
    private void OnMessageListView_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        if (m_MessageListView.SelectedItems.Count > 0)
        {
            int     itemIndex = m_MessageListView.SelectedItems[0].Index;
            Message message   = GetMessageInListView(itemIndex);
            if (message == null)
            {
                return;
            }

            m_DataGridView.Focus();
            DataGridViewUtility.SelectCell(m_DataGridView, message.Row, message.Column);
        }
    }
コード例 #3
0
ファイル: CsvForm.cs プロジェクト: yanshi7890/CsvEditor
    /// <summary>
    /// 插入行并添加Do事件到RedoUndo里
    /// </summary>
    private void OnInsertRowToolStripMenuItem_MouseDown(object sender, MouseEventArgs e)
    {
        m_DataGridView.CellValueChanged -= OnDataGridView_CellValueChanged;
        if (!Initialized)
        {
            return;
        }

        int offset             = 0;
        ToolStripMenuItem item = (ToolStripMenuItem)sender;

        if (item == m_InsertDownRowToolStripMenuItem)
        {
            offset = 1;
        }
        else if (item == m_InsertUpRowToolStripMenuItem)
        {
            offset = 0;
        }
        else
        {
            return;
        }
        if (m_DataGridView.SelectedRows.Count < 1)
        {
            return;
        }

        int index = m_DataGridView.SelectedRows[0].Index + offset;

        DataGridViewUtility.InsertNewRow(m_DataGridView, m_DataTable, index);

        m_DataGridView.ClearSelection();
        m_DataGridView.Rows[index].Selected = true;
        m_CopyDataTable = m_DataTable.Copy();
        EditManager.DidAddRow(index);

        OnDataGridViewData_Change();
        UpdateGridHeader();
        m_DataGridView.CellValueChanged += OnDataGridView_CellValueChanged;
    }
コード例 #4
0
        public void PasteFromClipBoard()
        {
            try
            {
                DataGridViewCell cell = this.dataGridView1.CurrentCell;

                if (cell != null)
                {
                    if (cell.ColumnIndex == 0)
                    {
                        MessageBox.Show("Pasting in the Date column is not supported");
                        return;
                    }
                }
                DataGridViewUtility u = new DataGridViewUtility(this.dataGridView1);
                u.PasteFromClipboard();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #5
0
    /// <summary>
    /// 插入行并添加Do事件到RedoUndo里
    /// </summary>
    private void OnInsertNewRowToolStripMenuItem_MouseDown(object sender, MouseEventArgs e)
    {
        if (!Initialized)
        {
            return;
        }

        int offset             = 0;
        ToolStripMenuItem item = (ToolStripMenuItem)sender;

        if (item == m_InsertNewRowToDownToolStripMenuItem)
        {
            offset = 1;
        }
        else if (item == m_InsertNewRowToUpToolStripMenuItem)
        {
            offset = 0;
        }
        else
        {
            return;
        }
        if (m_DataGridView.SelectedRows.Count < 1)
        {
            return;
        }

        BeforeChangeCellValue();
        int index = m_DataGridView.SelectedRows[0].Index + offset;

        DataGridViewUtility.InsertNewRow(m_DataGridView, m_DataTable, index);

        m_DataGridView.ClearSelection();
        m_DataGridView.Rows[index].Selected = true;
        EditManager.DidAddRow(index);

        UpdateGridHeader();
        AfterChangeCellValue();
    }
コード例 #6
0
 public void Redo(DataGridView dataGridView, DataTable dataTable)
 {
     DataGridViewUtility.InsertNewRow(dataGridView, dataTable, Row);
 }
コード例 #7
0
ファイル: CSVEditManager.cs プロジェクト: huangwwmm/CSVEditor
    /// <summary>
    /// UNDONE 这个方法是复制了PasetCells后修改的,应该想办法把这两个方法封装一下
    /// </summary>
    public void InsertFromClipboard(DataGridView dataGridView, DataTable dataTable, int rowIndex)
    {
        if (!CanInsertFromClipboard())
        {
            return;
        }

        if (!GetclipboardText(out string clipboardText))
        {
            return;
        }

        List <IUndoRedo> didManyThings = new List <IUndoRedo>();

        try
        {
            m_CSVForm.BeforeChangeCellValue();
            string[] lines = Regex.Split(clipboardText.TrimEnd("\r\n".ToCharArray()), "\r\n");
            // 当前行
            int currentRow = rowIndex;
            // 当前列
            int currentCol = 0;
            DataGridViewCell currentCell;
            for (int lineIdx = 0; lineIdx < lines.Length; lineIdx++)
            {
                // 插入行
                DataGridViewUtility.InsertNewRow(dataGridView, dataTable, currentRow);
                DoAddRowEvent doAddRowEvent = new DoAddRowEvent
                {
                    Row = currentRow
                };
                didManyThings.Add(doAddRowEvent);

                string line = lines[lineIdx];
                // 行超过表格限制,默认不添加新行
                if (currentRow >= dataGridView.RowCount)
                {
                    throw (new ArgumentOutOfRangeException(null,
                                                           string.Format("插入数据({0})行的第({1})行到表中第({2})行失败\n表一共有({3})行",
                                                                         lines.Length,
                                                                         lineIdx + 1,
                                                                         currentRow + 1,
                                                                         dataGridView.RowCount)));
                }

                string[] cells = line.Split('\t');
                List <CellValueChangeItem> cellChangeList = new List <CellValueChangeItem>();
                for (int cellIdx = 0; cellIdx < cells.Length; ++cellIdx)
                {
                    // 列超过表格限制,默认不添加新列
                    if (currentCol + cellIdx >= dataGridView.ColumnCount)
                    {
                        throw (new ArgumentOutOfRangeException(null,
                                                               string.Format("插入数据({0})列的第({1})列到表中第({2})列失败\n表一共有({3})列",
                                                                             cells.Length,
                                                                             cellIdx + 1,
                                                                             ConvertUtility.NumberToLetter(currentCol + cellIdx + 1),
                                                                             ConvertUtility.NumberToLetter(dataGridView.ColumnCount))));
                    }
                    currentCell = dataGridView.Rows[currentRow].Cells[currentCol + cellIdx];
                    string cell = cells[cellIdx];
                    if (currentCell.Value == null || currentCell.Value.ToString() != cell)
                    {
                        // 如果cell是多行数据,去除两侧的引号
                        if (cell.Contains("\n") && cell[0] == '"' && cell[cell.Length - 1] == '"')
                        {
                            cell = cell.Substring(1, cell.Length - 2);
                        }

                        CellValueChangeItem change = new CellValueChangeItem();
                        change.Row      = currentCell.RowIndex;
                        change.Column   = currentCell.ColumnIndex;
                        change.OldValue = (string)currentCell.Value;
                        change.NewValue = cell;

                        currentCell.Value = cell;
                        cellChangeList.Add(change);
                    }
                }
                DoCellsValueChangeEvent cellChangListEvent = new DoCellsValueChangeEvent
                {
                    ChangeList = cellChangeList
                };
                didManyThings.Add(cellChangListEvent);
                currentRow++;
            }
        }
        catch (ArgumentOutOfRangeException ex)
        {
            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK);
            // 粘贴失败,还原到粘贴前
#if !DEBUG
            if (didManyThings.Count > 0)
            {
                DoManyThingsEvent doManyThings = new DoManyThingsEvent
                {
                    ThingsList = didManyThings
                };

                doManyThings.Undo(dataGridView, null);
            }
            didManyThings = null;
#endif
        }
        catch (Exception ex)
        {
            DebugUtility.ShowExceptionMessageBox("粘贴到DataGridView失败", ex);
        }
        finally
        {
            DidManyThings(didManyThings);
            m_CSVForm.UpdateGridHeader();
            m_CSVForm.AfterChangeCellValue();
        }
    }