ColumnView.GetRowCellDisplayText(Int32, String) Method
Gets the display value of the specified cell.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
Parameters
Name | Type | Description |
---|---|---|
rowHandle | Int32 | An integer value specifying the handle of the row in which the desired cell resides. Row handles are not data source indexes, see the Accessing Rows in Code. Row Handles section of the “Rows” article for more information. |
fieldName | String | A string representing the field name of the column that contains the required cell. A ArgumentNullException exception will be thrown if the current View does not contain a column with the specified field name. |
Returns
Type | Description |
---|---|
String | A string representing the required cell’s display text. |
Remarks
Use the GetRowCellDisplayText method to obtain a textual representation of a specific cell’s value. The returned string is formatted as specified by the GridColumn.DisplayFormat property of the column in which the specified cell resides. If you need to obtain the cell’s actual value use the ColumnView.GetRowCellValue method.
The GetRowCellDisplayText method returns an empty string if the specified row handle doesn’t point to any of the rows within the current View or points to a group row.
For more information on row handles refer to the Rows document.
Note
In Instant Feedback Mode, this GetRowCellDisplayText method has limitations. It returns a correct value only if the target row has been loaded. Otherwise, it returns an empty string.
Note
Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the GetRowCellDisplayText member must not be invoked for these Views. The GetRowCellDisplayText member can only be used with Views that display real data within the Grid Control. Use the following methods to access these Views with which an end user interacts at runtime.
- GridControl.MainView - returns the top most View in a grid;
- GridControl.FocusedView - returns the focused View;
- GridControl.DefaultView - returns the currently maximized View;
- the sender parameter of View specific events;
- GridView.GetDetailView - returns a detail clone View for a specific master row.
Example
The following code shows how to select rows that contain “Mexico” in the Country column and copy data from these rows.
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
ColumnView view = gridControl1.MainView as ColumnView;
GridColumn colCountry = view.Columns["Country"];
GridColumn colCompany = view.Columns["CompanyName"];
if (colCountry == null || colCompany == null) return;
// Enable multiple row selection mode.
view.OptionsSelection.MultiSelect = true;
view.ClearSelection();
int rowHandle = -1;
// Select rows that contain 'Mexico' in the Country column.
while (rowHandle != GridControl.InvalidRowHandle) {
rowHandle = view.LocateByDisplayText(rowHandle + 1, colCountry, "Mexico");
view.SelectRow(rowHandle);
}
int[] selectedRowHandles = view.GetSelectedRows();
if (selectedRowHandles.Length > 0) {
// Move focus to the first selected row.
view.FocusedRowHandle = selectedRowHandles[0];
// Copy the selection to the clipboard
view.CopyToClipboard();
// Copy the selected company names to a Memo editor.
memoEdit1.Text = "";
for (int i = 0; i < selectedRowHandles.Length; i++)
memoEdit1.Text += view.GetRowCellDisplayText(selectedRowHandles[i], colCompany) + "\r\n";
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetRowCellDisplayText(Int32, String) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.