예제 #1
0
 private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!isEditMode)
     {
         CopyData.Pause(Clipboard.GetText(), tableView);
         statusLabel.Text = "粘贴成功";
     }
 }
예제 #2
0
        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!isEditMode)
            {
                Clipboard.SetText(CopyData.Copy(tableView.SelectedCells));
                //if (!string.IsNullOrWhiteSpace(selectCol))
                //{
                //    string text = tableView.SelectedCells[0].Value.ToString();
                //    //if (text == "")
                //    //{
                //    //    Clipboard.SetDataObject("");
                //    //   // Clipboard.SetText(" ");
                //    //}
                //    //else
                //    //{

                //    //}

                //}
                statusLabel.Text = "复制成功";
            }
        }
예제 #3
0
        public static void Pause(string copyData, DataGridView tableView)
        {
            CopyData data = null;

            try
            {
                data = FileManager.Deserialize <CopyData>(copyData);
            }
            catch (Exception)
            {
                return;
            }
            var cells = tableView.SelectedCells;
            List <DataGridViewCell> ignoreList = new List <DataGridViewCell>();

            for (int i = cells.Count - 1; i >= 0; i--)
            {
                var cell = cells[i];
                if (ignoreList.Contains(cell))
                {
                    continue;
                }

                foreach (var cellData in data.cellList)
                {
                    //tableView[cell.RowIndex + cellData.row, cell.ColumnIndex + cellData.col];
                    try
                    {
                        DataGridViewCell offsetCell = tableView[cell.ColumnIndex + cellData.col, cell.RowIndex + cellData.row];
                        if (offsetCell.OwningColumn.Name == DataTableExtend.IndexCol)
                        {
                            continue;
                        }
                        if (offsetCell.RowIndex >= tableView.Rows.Count - 1)
                        {
                            continue;
                        }
                        var intValue = 0;
                        if (string.IsNullOrWhiteSpace(cellData.value))
                        {
                            offsetCell.Value = DBNull.Value;
                        }
                        else
                        {
                            if (offsetCell.ValueType == typeof(int))
                            {
                                if (int.TryParse(cellData.value, out intValue))
                                {
                                    offsetCell.Value = intValue;
                                }
                                //else
                                //{
                                //    try
                                //    {
                                //        offsetCell.Value = cellData.value;
                                //    }
                                //    catch (Exception)
                                //    {
                                //    }

                                //}
                            }
                            else
                            {
                                offsetCell.Value = cellData.value;
                            }
                        }

                        ignoreList.Add(offsetCell);
                        offsetCell.ReadOnly = XmlTableEditor.IsXml(offsetCell.Value.ToString());
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }
        }