zoukankan      html  css  js  c++  java
  • DevExpress 如何向lookUpEditor中添加新值

    How to Use the ProcessNewValue Event of a LookUp Editor

    Tags:

    Alex Klim (DevExpress)16 years ago

    • How to Use the ProcessNewValue Event of a LookUp Editor

    Leave a Comment

    1 Solution

    Alex Klim (DevExpress)16 years ago

    ​​​​​​​

    The LookUp editor allows a user to enter values which cannot be found in the lookup list. A programmer should handle this situation, otherwise a new value is lost. The LookUp editor provides a ProcessNewValue event for this.

    First of all, you should set the SearchMode property to OnlyInPopup and TextEditStyle to Standard to enable free text entry.

    There are two common approaches for handling the ProcessNewValue event:
    1. Immediately insert the new record in the lookup table and generate a new ID for it.
    2. Display a dialog, where a user can set values for a new data row.

    Below are two code snippets which demonstrate the implementation of these approaches.

    
     

    [C#]Open in popup window

    // solution 1 
    
    private void LookUpEdit1_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e) {
    
       DataRow Row;
    
       RepositoryItemLookUpEdit Edit;
    
       Edit = ((LookUpEdit)sender).Properties;
    
    
    
       if(e.DisplayValue == null || Edit.NullText.Equals(e.DisplayValue) || string.Empty.Equals(e.DisplayValue))
    
           return;
    
    
    
       Row = LookupTable.NewRow();
    
       Row["Name"] = e.DisplayValue;
    
       LookupTable.Rows.Add(Row);
    
       
    
       e.Handled = true;
    
    }
    
    
    
    // solution 2 
    
    private void LookUpEdit1_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e) {
    
       DataRow Row;
    
       RepositoryItemLookUpEdit Edit;
    
       Edit = ((LookUpEdit)sender).Properties;
    
    
    
       if(e.DisplayValue == null || Edit.NullText.Equals(e.DisplayValue) || string.Empty.Equals(e.DisplayValue))
    
           return;
    
           
    
       using(Form2 f = new Form2()) {
    
           f.ItemID = "(Auto Number)";
    
           f.ItemName = e.DisplayValue.ToString();
    
           if(f.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) {
    
               e.DisplayValue = f.ItemName;
    
               Row = LookupTable.NewRow();
    
               Row["Name"] = f.ItemName;
    
               LookupTable.Rows.Add(Row);
    
           }
    
       }
    
           
    
       e.Handled = true;
    
    }
  • 相关阅读:
    《团队-爬取豆瓣Top250-团队一阶段互评》
    团队-爬虫豆瓣top250项目-开发文档
    结对总结
    课后作业-阅读任务-阅读提问-2
    2017-10-06-构建之法:现代软件工程-阅读笔记
    结对-结对编项目贪吃蛇-开发过程
    团队-爬取豆瓣电影TOP250-开发环境搭建过程
    个人-GIT使用方法
    课后作业-阅读任务-阅读提问-1
    课后作业-阅读任务-阅读笔记-1
  • 原文地址:https://www.cnblogs.com/grj001/p/12225303.html
Copyright © 2011-2022 走看看