Exemplo n.º 1
0
        protected virtual void WriteData(IProgressMonitor progressMonitor, TextWriter writer, BindingListView bindingListView, IDataFormat dataFormat)
        {
            var tempBindingListView = new BindingListView(new ViewInfo(ParentColumn, bindingListView.GetViewSpec()), bindingListView.ToArray());
            var tempDataGridView    = new BoundDataGridView
            {
                DataSource         = new BindingSource(tempBindingListView, ""),
                SelectionMode      = DataGridViewSelectionMode.FullRowSelect,
                ClipboardCopyMode  = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText,
                RowHeadersVisible  = false,
                Visible            = false,
                BindingContext     = new BindingContext(),
                AllowUserToAddRows = false,
            };

            using (tempDataGridView)
            {
                var status = new ProgressStatus("Writing " + tempDataGridView.Rows.Count + " rows");
                dataFormat.WriteRow(writer, tempDataGridView.Columns.Cast <DataGridViewColumn>().Select(column => column.HeaderCell.EditedFormattedValue));
                var rowCount = tempDataGridView.Rows.Count;
                for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
                {
                    if (progressMonitor.IsCanceled)
                    {
                        return;
                    }
                    status = status.ChangeMessage("Writing row " + (rowIndex + 1) + "/" + rowCount)
                             .ChangePercentComplete(rowIndex * 100 / rowCount);
                    progressMonitor.UpdateProgress(status);
                    var row = tempDataGridView.Rows.SharedRow(rowIndex);
                    dataFormat.WriteRow(writer,
                                        row.Cells.Cast <DataGridViewCell>()
                                        .Select(cell => cell.GetEditedFormattedValue(rowIndex, DataGridViewDataErrorContexts.Formatting | DataGridViewDataErrorContexts.ClipboardContent)));
                }
            }
        }