Example E285
Visible to All Users

WinForms Lookup - Process new values (ProcessNewValue event)

This example handles the ProcessNewValue event to parse entered values and add new records to the lookup's data source. Read the following KB article for additional information: How to Use the ProcessNewValue Event of a LookUp Editor.

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors.Repository; using DevExpress.XtraEditors; namespace ProcessNewValueSample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void FillLookupTable() { const int RowCount = 5; DataRow Row; for(int i = 1; i <= RowCount; i++) { Row = LookupTable.NewRow(); Row["Name"] = "Item " + i.ToString(); LookupTable.Rows.Add(Row); } LookupTable.AcceptChanges(); } private void Form1_Load(object sender, System.EventArgs e) { FillLookupTable(); LookUpEdit1.Properties.DataSource = LookupTable; LookUpEdit1.Properties.ValueMember = "ID"; LookUpEdit1.Properties.DisplayMember = "Name"; LookUpEdit1.Properties.PopulateColumns(); LookUpEdit1.Properties.AutoSearchColumnIndex = 1; LookUpEdit1.Properties.DropDownRows = 20; LookUpEdit1.Properties.ValidateOnEnterKey = true; LookUpEdit1.Properties.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.OnlyInPopup; LookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard; } private void LookUpEdit1_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e) { Console.WriteLine("LookUpEdit1_ProcessNewValue: {0}", e.DisplayValue); DataRow Row; RepositoryItemLookUpEdit Edit; Edit = ((LookUpEdit)sender).Properties; if(e.DisplayValue == null || Edit.NullText.Equals(e.DisplayValue) || string.Empty.Equals(e.DisplayValue)) return; if((int)RadioGroup1.EditValue == 1) { // solution 1 Row = LookupTable.NewRow(); Row["Name"] = e.DisplayValue; LookupTable.Rows.Add(Row); } else // solution 2 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; } } }
Form2.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ProcessNewValueSample { public partial class Form2 : Form { public object ItemID { get { return TextEdit1.EditValue; } set { TextEdit1.EditValue = value; } } public string ItemName { get { return TextEdit2.Text; } set { TextEdit2.EditValue = value; } } public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.