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))); } } }
public static RowItemValues FromDataGridView(Type propertyType, BoundDataGridView dataGridView) { if (dataGridView == null) { return(Empty(propertyType)); } var bindingSource = dataGridView.DataSource as BindingListSource; if (bindingSource == null) { return(Empty(propertyType)); } return(FromItemProperties(propertyType, bindingSource.ItemProperties)); }
public IEnumerable <RowItem> GetSelectedRowItems(BoundDataGridView dataGridView) { var bindingSource = dataGridView.DataSource as BindingListSource; if (bindingSource == null) { return(new RowItem[0]); } if (dataGridView.SelectedRows.Count == 0) { var currentRow = bindingSource.Current as RowItem; if (currentRow == null) { return(new RowItem[0]); } return(new[] { currentRow }); } return(dataGridView.SelectedRows.Cast <DataGridViewRow>() .Select(row => (RowItem)bindingSource[row.Index])); }