IDataStore.IndexOf<TModel>(TModel item) Method
.NET Standard 2.x
Determines the index number of a specific model instance in the primary buffer of DataStore. This index is the same as the zero-based row number in the primary buffer.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public int IndexOf<TModel>(TModel item);
Parameters
item
TModel
The model object of a row to locate in the primary buffer.
The type of the model class must match with the current DataObject
.
Returns
System.Int32
Returns the zero-based index of the model object in the primary buffer if found; otherwise, -1
.
Examples
The following code example demonstrates how to get the index of a row item.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class IndexOfExample
{
private readonly SchoolContext _context;
public IndexOfExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
datastore.Retrieve();
// Gets the department object of the first row
var department = datastore.GetModel<D_Department>(0);
// Gets the row number of department object in the datastore
// It is the first row in datastore, so 0 should be returned
int row = datastore.IndexOf(department);
Console.WriteLine("Row: {0}", row);
// Sorts datastore by departmentid desc.
// The record in the first row is moved to the fourth row.
datastore.SetSort("departmentid desc");
datastore.Sort();
row = datastore.IndexOf(department);
Console.WriteLine("Row: {0}", row);
/*This code produces the following output:
Row: 0
Row: 3
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x