Ejemplo n.º 1
0
        /// <summary>The copy tool strip menu item_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CopyForm win = null;

            try
            {
                DataGridView grid = (DataGridView)_resultsTabControl.SelectedTab.Controls[0];

                if (grid.SelectedCells.Count == 0)
                {
                    return;
                }

                win = new CopyForm();

                if (win.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                SortedList headers = new SortedList();
                SortedList rows    = new SortedList();

                string delimiter = win.Delimiter;
                string line      = string.Empty;

                for (int i = 0; i < grid.SelectedCells.Count; i++)
                {
                    DataGridViewCell   cell = grid.SelectedCells[i];
                    DataGridViewColumn col  = cell.OwningColumn;

                    if (!headers.ContainsKey(col.Index))
                    {
                        headers.Add(col.Index, col.Name);
                    }

                    if (!rows.ContainsKey(cell.RowIndex))
                    {
                        rows.Add(cell.RowIndex, cell.RowIndex);
                    }
                }

                if (win.IncludeHeaders)
                {
                    for (int i = 0; i < headers.Count; i++)
                    {
                        line += (string)headers.GetByIndex(i);
                        if (i != headers.Count)
                        {
                            line += delimiter;
                        }
                    }

                    line += "\r\n";
                }

                for (int i = 0; i < rows.Count; i++)
                {
                    DataGridViewRow            row   = grid.Rows[(int)rows.GetKey(i)];
                    DataGridViewCellCollection cells = row.Cells;

                    for (int j = 0; j < headers.Count; j++)
                    {
                        DataGridViewCell cell = cells[(int)headers.GetKey(j)];

                        if (cell.Selected)
                        {
                            line += cell.Value;
                        }

                        if (j != (headers.Count - 1))
                        {
                            line += delimiter;
                        }
                    }

                    line += "\r\n";
                }

                if (!string.IsNullOrEmpty(line))
                {
                    Clipboard.Clear();
                    Clipboard.SetText(line);

                    _hostWindow.SetStatus(this, "Selected data has been copied to your clipboard");
                }
            }
            finally
            {
                if (win != null)
                {
                    win.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>The copy tool strip menu item_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CopyForm win = null;

            try
            {
                DataGridView grid = (DataGridView)_resultsTabControl.SelectedTab.Controls[0];

                if (grid.SelectedCells.Count == 0)
                {
                    return;
                }

                win = new CopyForm();

                if (win.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                SortedList headers = new SortedList();
                SortedList rows = new SortedList();

                string delimiter = win.Delimiter;
                string line = string.Empty;

                for (int i = 0; i < grid.SelectedCells.Count; i++)
                {
                    DataGridViewCell cell = grid.SelectedCells[i];
                    DataGridViewColumn col = cell.OwningColumn;

                    if (!headers.ContainsKey(col.Index))
                    {
                        headers.Add(col.Index, col.Name);
                    }

                    if (!rows.ContainsKey(cell.RowIndex))
                    {
                        rows.Add(cell.RowIndex, cell.RowIndex);
                    }
                }

                if (win.IncludeHeaders)
                {
                    for (int i = 0; i < headers.Count; i++)
                    {
                        line += (string)headers.GetByIndex(i);
                        if (i != headers.Count)
                        {
                            line += delimiter;
                        }
                    }

                    line += "\r\n";
                }

                for (int i = 0; i < rows.Count; i++)
                {
                    DataGridViewRow row = grid.Rows[(int)rows.GetKey(i)];
                    DataGridViewCellCollection cells = row.Cells;

                    for (int j = 0; j < headers.Count; j++)
                    {
                        DataGridViewCell cell = cells[(int)headers.GetKey(j)];

                        if (cell.Selected)
                        {
                            line += cell.Value;
                        }

                        if (j != (headers.Count - 1))
                        {
                            line += delimiter;
                        }
                    }

                    line += "\r\n";
                }

                if (!string.IsNullOrEmpty(line))
                {
                    Clipboard.Clear();
                    Clipboard.SetText(line);

                    _hostWindow.SetStatus(this, "Selected data has been copied to your clipboard");
                }
            }
            finally
            {
                if (win != null)
                {
                    win.Dispose();
                }
            }
        }