Dev GridView 内置Lookup组件同时操作编号和名称
作者:C/S框架网  发布日期:2016-12-21 10:50:34
  Dev GridView 内置Lookup组件同时操作编号和名称


C# Code:

public partial class Form1 : Form
{
   public Form1()
   {
      InitializeComponent();
   }
   
   private void Form1_Load(object sender, EventArgs e)
   {
      gridControl1.DataSource = GetOrder();
      
      //选择,显示编号
      repositoryItemLookUpEdit1.DisplayMember = "CustomerCode";// here!
      repositoryItemLookUpEdit1.ValueMember = "CustomerCode";
      repositoryItemLookUpEdit1.DataSource = GetLookupData();
   }
   
   private object GetLookupData()
   {
      DataTable dt = new DataTable();
      dt.Columns.Add("CustomerCode", typeof(String));
      dt.Columns.Add("CustomerName", typeof(String));
      dt.Rows.Add("ZX", "中兴通讯");
      dt.Rows.Add("HW", "华为科技");
      dt.Rows.Add("TENCENT", "腾讯科技");
      dt.Rows.Add("ALI", "阿里巴巴");
      dt.AcceptChanges();
      return dt;
   }
   
   private object GetOrder()
   {
      DataTable dt = new DataTable();
      dt.Columns.Add("OrderID", typeof(String));
      dt.Columns.Add("CustomerCode", typeof(String));
      dt.Columns.Add("CustomerName", typeof(String));
      dt.Columns.Add("Price", typeof(String));
      dt.Rows.Add("ID000001", "HW", "华为科技", 1001.00);
      dt.Rows.Add("ID000002", "ZX", "中兴通讯", 99.00);
      dt.Rows.Add("ID000003", "TENCENT", "腾讯科技", 120.00);
      dt.AcceptChanges();
      return dt;
   }
   
   private void gridView1_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
   {
      if (e.Column.FieldName == "CustomerCode")
      {
         object dataRow = repositoryItemLookUpEdit1.GetDataSourceRowByKeyValue(e.Value);
         object value = (dataRow as DataRowView)["CustomerName"];
         gridView1.SetFocusedRowCellValue("CustomerName", value);
      }
   }
}

//来源:C/S框架网(www.csframework.com) QQ:1980854898




贴图图片




贴图图片
上一篇 下一篇