CustomColumnDataEventArgs.ListSourceRowIndex Property
Gets the current row’s index in the data source.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v19.2.dll
Declaration
Property Value
Type | Description |
---|---|
Int32 | An integer value identifying the current row’s index in the data source. |
Remarks
Use the ListSourceRowIndex property to refer to the current row using the methods provided by your data source.
To get values in the row identified by the ListSourceRowIndex property, use the ColumnView.GetListSourceRowCellValue method.
Example 1
Assume that the Grid Control is bound to a table that contains the “Quantity”, “UnitPrice” and “Discount” columns. The example below shows how to add an unbound column to the grid to display the amount of each order according to the expression: QuantityUnitPrice(1-Discount).
The result is displayed below:
For another example which illustrates working with unbound columns, see the Unbound Columns tutorial.
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
private void Form1_Load(object sender, System.EventArgs e) {
// ...
gridControl1.ForceInitialize();
// Create an unbound column.
GridColumn unbColumn = gridView1.Columns.AddField("Total");
unbColumn.VisibleIndex = gridView1.Columns.Count;
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
// Disable editing.
unbColumn.OptionsColumn.AllowEdit = false;
// Specify format settings.
unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
unbColumn.DisplayFormat.FormatString = "c";
// Customize the appearance settings.
unbColumn.AppearanceCell.BackColor = Color.LemonChiffon;
}
// Returns the total amount for a specific row.
decimal getTotalValue(GridView view, int listSourceRowIndex) {
decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "UnitPrice"));
decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity"));
decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Discount"));
return unitPrice * quantity * (1 - discount);
}
// Provides data for the Total column.
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
GridView view = sender as GridView;
if (e.Column.FieldName == "Total" && e.IsGetData) e.Value =
getTotalValue(view, e.ListSourceRowIndex);
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ListSourceRowIndex property.
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.