Skip to content

Display custom text if the lookup's value is not found in the dropdown list.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/winforms-lookup-display-custom-text-for-not-found-edit-value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Lookup - Display custom text if the lookup's value is not found in the drop-down list

This example handles the Properties.CustomDisplayText event to display custom text if the lookup's EditValue does not match any value in the drop-down list (the value does not exist in the data source).

const string NotFoundText = "???";

private void RepositoryItemLookUpEdit_CustomDisplayText(object sender, CustomDisplayTextEventArgs e) {
    RepositoryItemLookUpEdit props;
    if(sender is LookUpEdit)
        props = (sender as LookUpEdit).Properties;
    else
        props = sender as RepositoryItemLookUpEdit;
    
    if(props != null && (e.Value is int)) {
        object row = props.GetDataSourceRowByKeyValue(e.Value);
        if(row == null) {
            e.DisplayText = NotFoundText;
        }
    }
}

Files to Review

Documentation

See Also