Bind Data source:
Lookupedit. properties. valuemember = actually used field; // equivalent to editvalue
Lookupedit. properties. displaymember = field to be displayed; // equivalent to text
Lookupedit. properties. datasource = data source;
Determine whether to select the drop-down list:
If (this. lookupedit. editvalue = null | this. lookupedit. editvalue. tostring () = "nulltext ")
{
// The prompt message indicating that no drop-down box is selected
}
Clear nulltext value:
Lookupedit. properties. nulltext = null;
Set the nulltext value:
Lookupedit. properties. nulltext = "Please select ";
Use the value of lookupedit1:
Variable = this. lookupedit. editvalue. tostring () // is the value of ookupedit. properties. valuemember
Variable = this. lookupedit. text. trim () // The value of ookupedit. properties. displaymember
It is particularly worth noting that sometimes we need to use lookupedit to achieve some of the effects of combox. during actual use, the first item will be selected by default when the program is loaded. Its settings are as follows:
Lookupedit. itemindex = 0; // select the first item
Lookupedit. itemindex =-1; // no option. In this case, the nulltext value is displayed. In fact, as long as editvalue = null, lookupedit displays nulltext.
Lookupedit1.editvalue = value; // automatically searches for datasouse and selects the matched value. If no value exists, the value is null. The value must be of the same data type as valuemember.
However, when you select a record for lookupedit, bindingsourse. the value of current is always the first record. To obtain the record of your data source, you must use lookupedit. getdatasoursebykeyvalue (keyvalue) and (object) are forcibly transferred. However, you must note that the keyvalue must be the primary key of your data source. Otherwise, you obtain the first record with the same key. What if multiple key values determine a record?
Dev express also has a corresponding solution, that is, using gridlookupedit, which should be a combination of gridview and lookupedit. You can use this to select records with the same primary key, use gridlookupeditview. getdatasourcerowindex (gridlookupeditview. focusedrowhandle.
If you do not want to display [EditValue is null] In the lookupedit box during running, set the EditValue attribute Type to the String Type. If the Value is empty, it is OK.
Similarly, for the lookupedit field in gridControl, you only need to set the NullText attribute to null.