본문 바로가기
C#/DevExpress

DevExpress / Winform LookUpEdit 컨트롤에서 NULL 값에 텍스트 입력하기.

by HyunS_ 2019. 4. 15.
728x90

LookUpEdit.Properties.NullText 를 통하여 Null 값을 나타내는 텍스트를 가져 오거나 설정할 수 있습니다.

 

public class CityInfo 
{
    public int ID { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
    public string Region { get; set; }
}
List<Person> Persons = new List<Person>();
List<CityInfo> Cities = new List<CityInfo>();

CreateData();
            
LookUpEdit lookUpEdit = new LookUpEdit();
lookUpEdit.Parent = this;
lookUpEdit.Location = new System.Drawing.Point(198,78);
lookUpEdit.Size = new System.Drawing.Size(199,20);

lookUpEdit.DataBindings.Add(new Binding("EditValue", Persons, "CityID"));
lookUpEdit.Properties.DataSource = Cities;
lookUpEdit.Properties.ValueMember = "ID";
lookUpEdit.Properties.DisplayMember = "City";
lookUpEdit.Properties.PopulateColumns();+

lookUpEdit.Properties.NullText = "NULL TEXT 입니다."; 

lookUpEdit.CustomDisplayText += LookUpEdit_CustomDisplayText;

private void CreateData()
{
      Cities.Add(new CityInfo() { ID = 0, City= "Barquisimeto", Country= "Venezuela", Region="Lara" });
      Cities.Add(new CityInfo() { ID = 1, City = "Rio de Janeiro", Country = "Brazil", Region = "RJ" });
      Cities.Add(new CityInfo() { ID = 2, City = "Cunewalde", Country = "Germany", Region = "" });
      Cities.Add(new CityInfo() { ID = 3, City = "Madrid", Country = "Spain", Region = "" });
      Cities.Add(new CityInfo() { ID = 4, City = "Charleroi", Country = "Belgium", Region = "" });
      Cities.Add(new CityInfo() { ID = 5, City = "Sao Paulo", Country = "Brazil", Region = "SP" });
}

private void LookUpEdit_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
{
	LookUpEdit lookUpEdit = sender as LookUpEdit;

	CityInfo city = lookUpEdit.Properties.GetDataSourceRowByKeyValue(e.Value) as CityInfo;
	if(city!=null) 
    {
		e.DisplayText = (sender as LookUpEdit).Properties.NullText;
	}
}
728x90

댓글