Skip to main content

RepositoryItemLookUpEdit.GetDataSourceRowIndex(String, Object) Method

Returns the visual index of the row in the dropdown that contains the specified value in the specified field.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public virtual int GetDataSourceRowIndex(
    string fieldName,
    object value
)

Parameters

Name Type Description
fieldName String

A string that is the field whose values will be compared with the specified value to locate the required row.

value Object

A value contained in the required row in the specified field.

Returns

Type Description
Int32

An integer value that is the row’s zero-based visual index in the dropdown. -1 if such a row is not found.

Remarks

Use the GetDataSourceRowIndex method to obtain the visible index of a row in the dropdown that contains the specified value in the specified data field (even if there is no any column in the RepositoryItemLookUpEdit.Columns collection bound to this field).

The index returned can be used to obtain the row’s specific value via the RepositoryItemLookUpEdit.GetDataSourceValue method.

To get the index of a specific row in the underlying data source, use the RepositoryItemLookUpEdit.GetListSourceIndex method.

using System;
using DevExpress.XtraEditors;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace DXApplication23 {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            lookUpEdit1.Properties.DataSource = Employee.GetSampleData();
            // Sets the lookup's data fields.
            lookUpEdit1.Properties.DisplayMember = "FullName";
            lookUpEdit1.Properties.ValueMember = "ID";
            // Sets the lookup's value. Selects the first record.
            lookUpEdit1.EditValue = 0;
            lookUpEdit1.Properties.ForceInitialize();
            lookUpEdit1.Properties.PopulateColumns();
        }
        int GetLastNameRowIndex(string lastName) {
            return lookUpEdit1.Properties.GetDataSourceRowIndex("LastName", lastName);
        }
    }
    public class Employee {
        public Employee(int iD, string firstName, string lastName) {
            ID = iD;
            FirstName = firstName;
            LastName = lastName;
        }
        public static List<Employee> GetSampleData() {
            return new List<Employee>() {
            new Employee(0, "Bart", "Arnaz"),
            new Employee(1, "Leah", "Simpson"),
            new Employee(2, "Arnold", "Schwartz"),
            new Employee(3, "William", "Zimmer"),
            new Employee(4, "Samantha", "Piper")
        };
        }
        // The 'ID' field must contain unique values.
        public int ID { get; private set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        [Display(Order = -1)]
        public string FullName {
            get {
                return string.Format("{0} {1}", FirstName, LastName);
            }
        }
    }
}
See Also