DataGridViewCell.GetClipboardContent(Int32, Boolean, Boolean, Boolean, Boolean, String) 方法

定义

检索要复制到 Clipboard 的单元格的已设置格式的值。Retrieves the formatted value of the cell to copy to the Clipboard.

protected:
 virtual System::Object ^ GetClipboardContent(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, System::String ^ format);
protected virtual object GetClipboardContent (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format);
abstract member GetClipboardContent : int * bool * bool * bool * bool * string -> obj
override this.GetClipboardContent : int * bool * bool * bool * bool * string -> obj
Protected Overridable Function GetClipboardContent (rowIndex As Integer, firstCell As Boolean, lastCell As Boolean, inFirstRow As Boolean, inLastRow As Boolean, format As String) As Object

参数

rowIndex
Int32

包含该单元格的行从零开始的索引。The zero-based index of the row containing the cell.

firstCell
Boolean

若单元格位于由选定单元格定义的区域的第一列,则为 true;否则为 falsetrue to indicate that the cell is in the first column of the region defined by the selected cells; otherwise, false.

lastCell
Boolean

若单元格位于由选定单元格定义的区域的最后一列,则为 true;否则为 falsetrue to indicate that the cell is the last column of the region defined by the selected cells; otherwise, false.

inFirstRow
Boolean

若单元格位于由选定单元格定义的区域的第一行,则为 true;否则为 falsetrue to indicate that the cell is in the first row of the region defined by the selected cells; otherwise, false.

inLastRow
Boolean

如果该单元格位于选定单元格所定义区域内的最后一行中,则为 true;否则为 falsetrue to indicate that the cell is in the last row of the region defined by the selected cells; otherwise, false.

format
String

单元格的当前格式字符串。The current format string of the cell.

返回

Object

Object,它表示要复制到 Clipboard 的单元格的值。An Object that represents the value of the cell to copy to the Clipboard.

例外

rowIndex 小于 0 或大于等于控件中的行数。rowIndex is less than 0 or greater than or equal to the number of rows in the control.

单元格的 DataGridView 属性的值是 nullThe value of the cell's DataGridView property is null.

-或--or- ColumnIndex 小于 0,这表示该单元格为行标头单元格。ColumnIndex is less than 0, indicating that the cell is a row header cell.

格式化失败,这是由于 DataError 控件的 DataGridView 事件无处理程序或处理程序将 ThrowException 属性设置为 true 而引起的。Formatting failed and either there is no handler for the DataError event of the DataGridView control or the handler set the ThrowException property to true. 通常情况下,可将该异常对象强制转换为类型 FormatExceptionThe exception object can typically be cast to type FormatException.

注解

此方法由 DataGridView.GetClipboardContent 方法调用,用于检索表示单元格值的剪贴板格式的值。This method is called by the DataGridView.GetClipboardContent method to retrieve a Clipboard-formatted value that represents the cell value.

单元格值首先从方法的显示格式中检索 GetEditedFormattedValueThe cell value is first retrieved in its display format from the GetEditedFormattedValue method. DataGridView.CellFormatting如果格式设置不成功,则这可能会引发事件来设置值的格式,并引发 DataGridView.DataError 事件。This may raise the DataGridView.CellFormatting event to format the value and the DataGridView.DataError event if formatting is unsuccessful.

此方法的位置相关参数指示此单元格位于数据表中的位置,该数据表示控件中的选定单元格定义的区域 DataGridViewThe position-related parameters of this method indicate where this cell is located in the table of data representing the region defined by the selected cells in the DataGridView control. 根据单元格的位置,此方法可能会返回附加格式设置信息以及显示格式单元值。Depending on the cell's position, additional formatting information may be returned by this method along with the display-formatted cell value. 例如,行第一列中的单元格的 HTML 格式将包括指示行的开头的标记。For example, the HTML format for a cell in the first column of a row will include the tag that indicates the beginning of a row.

支持的剪贴板格式包括 DataFormats.TextDataFormats.UnicodeTextDataFormats.HtmlDataFormats.CommaSeparatedValueThe supported Clipboard formats include DataFormats.Text, DataFormats.UnicodeText, DataFormats.Html, and DataFormats.CommaSeparatedValue.

有关更多信息,请参见 Clipboard 类。For more information, see the Clipboard class.

继承者说明

重写此方法以提供自定义的剪贴板值。Override this method to provide customized Clipboard values. 例如,可以重写此方法,以支持从自定义单元格类型复制值。For example, you could override this method to support copying values from custom cell types.

适用于

另请参阅