We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Is it possible to automatically change GridMultiColumnDropDownList ItemsSource if the user type a code that does not exist?

Thread ID:

Created:

Updated:

Platform:

Replies:

131149 Jun 23,2017 10:41 AM Jun 28,2017 09:45 PM WPF 3
loading
Tags: SfDataGrid
Silvio
Asked On June 23, 2017 10:41 AM

Hi,

please find here attached an example that I have modified to ask you a question and a video where I better explain my question (Question about GridMultiColumnDropDownList.wmv).

I have a GridMultiColumnDropDownList column that is binded to a collection of Product objects named ProductList.
The user can edit the cells in this column, but by default, if he types a Product Code that does not exist and presses Enter, his changes are not considered since the inserted Code is not found in the underlying collection.
But I'd like, instead, that, if a user types a Code that does not exist in the binded collection, a new Product is automatically created (with a new incremental ID) and added to the ProductList collection. So everything the user types in the column, even if it does not exist as a Code, it is automatically added to the Product collection and Order object is correctly updated with the user's changes.

Is it possible to implement such a behaviour?
Can you suggest me any idea?

Thank you.

Silvio

Attachment: Combo_columns_for_grids_3001a5d7.zip

Srinivasan Vasu [Syncfusion]
Replied On June 27, 2017 05:41 AM

Hi Silvio, 
 
Sorry for delay caused. 
 
We have checked your query and we have prepared a sample as per your requirement. You can achieve your requirement by customizing the GridCellMultiColumnDropDownRenderer. 
 
Please refer the below code. 
 
   this.Grid.CellRenderers.Remove("MultiColumnDropDown"); 
   this.Grid.CellRenderers.Add("MultiColumnDropDown", new MultiDropDownRenderer()); 
 
public class MultiDropDownRenderer: GridCellMultiColumnDropDownRenderer 
    {        
        protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) 
        {             
            if (e.Key == Key.Enter) 
            { 
                var multiDropDown = (this.CurrentCellRendererElement as SfMultiColumnDropDownControl); 
                var textBox = multiDropDown.GetType().GetProperty("Editor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(multiDropDown);                 
                var newValue = textBox != null ? (textBox as TextBox).Text : null; 
                var underlyingItems = (this.DataGrid.DataContext as ViewModel).ProductList; 
 
                if (underlyingItems != null) 
                { 
                    bool newRecord = underlyingItems.Any(x => x.Code == newValue.ToString()); 
                    if (!newRecord) 
                    { 
                        underlyingItems.Add(new ProductInfo() { Code = newValue.ToString(), ID = underlyingItems.Count + 1  }); 
                        multiDropDown.SelectedItem = underlyingItems.Last(); 
                    } 
                } 
            } 
            return base.ShouldGridTryToHandleKeyDown(e); 
        } 
    } 
 
Please download the sample from the below location. 
 
 
 
Regards,
Srinivasan 


Silvio
Replied On June 28, 2017 05:37 AM

very very helpful!

Thank you!


Srinivasan Vasu [Syncfusion]
Replied On June 28, 2017 09:45 PM

Hi Silvio, 
  
Thanks for your update. 
  
Please let us know if need further asssitance. 
  
Regards, 
Srinivasan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;