Basic usage of devexpress. xtraeditors. lookupedit

Source: Internet
Author: User

In ** _ load

First, the data obtained from the DB: sqldatareader mydatareader = mycommand. executereader ();

Then, using (datatable dt = new datatable ())
{
DT. Load (mydatareader );
Lokpurchaseslipkbn. properties. datasource = DT;
Lokpurchaseslipkbn. properties. displaymember = "kbn_control_kbn ";
Lokpurchaseslipkbn. properties. valuemember = "l_name ";

Column appending
Lookupcolumninfocollection colcollection1 = lokpurchaseslipkbn. properties. columns;
Colcollection1.clear ();
Colcollection1.add (New lookupcolumninfo ("l_name", "", 0 ));
Int dropdown1 = (Dt = NULL | DT. Rows. Count> lok_view_maxrow )? Lok_view_maxrow: DT. Rows. count;
Lokpurchaseslipkbn. properties. dropdownrows = dropdown1;
Lokpurchaseslipkbn. properties. bestfit ();
Lokpurchaseslipkbn. properties. pupwidth = 100;
}

Usage of the gridview: First, you must configure the view, and then the usage is the same.

Properties. nulltest = [not selected], when lookupedit selects another value, properties. allownullinput = true;

 

Data Binding example of the lookupedit Control

 

Try

{

Kpmisdatabase Dc = new kpmisdatabase ();

Ddloutorg. properties. Columns. Clear ();

VaR query = from o in DC. bas_organization

Join P in DC. fin_orgaccount

On O. org_id equals P. org_id

Where p. acct_status = "normal"

Select New

{

O. org_id,

O. org_name

};

Datatable dt = query. Distinct (). todatatable (Rec => new object [] {query });

If (Dt. Rows. Count> 0)

{

Datarow DR = DT. newrow ();

Dr ["org_id"] = "";

Dr ["org_name"] = "-- select --";

DT. Rows. insertat (DR, 0 );

Ddloutorg. properties. Columns. Add (New lookupcolumninfo ("org_name "));

Ddloutorg. properties. valuemember = "org_id ";

Ddloutorg. properties. displaymember = "org_name ";

Ddloutorg. properties. datasource = DT;

Ddloutorg. editvalue = DT. Rows [0] ["org_id"];

}

Else

{

Ddloutorg. properties. datasource = NULL;

Ddloutorg. properties. nulltext = "-- no data --";

}

}

Catch (exception ex)

{

Msgbox. errshow (ex. Message );

}

 

Dev control lookupedit setting option value

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.

 

 

Comboboxedit Data Binding


<Sorting: Glacier fishermen>

Comboboxedit is often used in the devexpress winform control. We may sometimes need to bind data to the comboboxedit control while the comboboxedit control does not have the datasource attribute as the lookupedit control, you can bind a dataset directly.
Next we use comboboxedit's comboboxedit1.properties. Items. Add (Object item) method to bind data.

1. First Use the getareadatatable method to return a datatable. The Code is as follows:
Public static datatable getareadatatable ()
{
String sqlstr = "select BMMC from usiclb where bmlid = 3 ";
Database DB = new database ();
Datatable dt = dB. getdatatable (sqlstr );
Return DT;
}

2. Add the data loop to comboboxedit. The Code is as follows:
Private void loadcomboboxedit ()
{
This. comboboxedit1.properties. nulltext = "Select ...";
Datatable dt = userinfo. getareadatatable ();
For (INT I = 0; I <DT. Rows. Count; I ++)
{
Comboboxedit1.properties. Items. Add (Dt. Rows [I] ["BMMC"]. tostring ());
}
}

 

 

Allow custom value input

Lookupeditor1.properties. texteditstyle = devexpress. xtraeditors. Controls. texteditstyles. Standard;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.