lookupedit devexpress get specific row

How to Get a Specific Row using DevExpress LookupEdit

If you are working with DevExpress LookupEdit in your project, you might need to get a specific row based on certain criteria. Here is how you can do it:

Method 1: Using the EditValue property

The EditValue property of the LookupEdit returns the selected value. In order to get a specific row based on a certain value, you can loop through the rows of the lookup edit until you find the row with the desired value.


// Get the LookupEdit control
LookupEdit lookupEdit = new LookupEdit();

// Get the desired value
int desiredValue = 42;

// Loop through the rows of the lookup edit
foreach (DataRowView row in lookupEdit.Properties.DataSource)
{
    // Get the value of the current row
    int currentValue = Convert.ToInt32(row["Value"]);

    // Check if the current row is the desired row
    if (currentValue == desiredValue)
    {
        // Get the data row of the desired row
        DataRow desiredRow = row.Row;

        // Do something with the desired row
        break;
    }
}

Method 2: Using the GetDataSourceRowIndex method

The LookupEdit control provides a method called GetDataSourceRowIndex which allows you to get the index of a row based on its value.


// Get the LookupEdit control
LookupEdit lookupEdit = new LookupEdit();

// Get the desired value
int desiredValue = 42;

// Get the index of the desired row
int rowIndex = lookupEdit.Properties.GetDataSourceRowIndex("Value", desiredValue);

// Get the data row of the desired row
DataRow desiredRow = ((DataView)lookupEdit.Properties.DataSource)[rowIndex].Row;

// Do something with the desired row

These are the two methods that you can use to get a specific row using DevExpress LookupEdit control. Choose the one that suits your needs and implement it in your project!

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe