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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridMultiColumnDropDownList allow values not in list

Thread ID:

Created:

Updated:

Platform:

Replies:

145420 Jun 20,2019 02:34 PM UTC Mar 29,2021 05:19 AM UTC WPF 18
loading
Tags: SfDataGrid
Ondrej Svoboda
Asked On June 20, 2019 02:34 PM UTC

Hi,
is there a way how to use values not GridMultiColumnDropDownList's list?

My scenario is that drop down list contains only most used values - user can choose from them or enter other value by hand. 
Right now when cell contains a value not in GridMultiColumnDropDownList's list blank value is displayed and I also didnt find a way how to enter value not in list.

Thanks
Ondřej Svoboda

Shobika Palani [Syncfusion]
Replied On June 21, 2019 11:42 AM UTC

Hi Ondrej, 

Thank you for contacting Syncfusion Support. 

We have analyzed your query to enter a value that is not in the list of GridMultiDropDownList.  

Could you please let us know whether your requirement is to have same itemsSource for the rows in multi dropdown column or to load different itemssource for different rows as like ItemsSourceSelector behavior in GridComboBoxColumn? It will helps us to investigate further and provide appropriate solution at earlier. 

Regards, 
Shobika. 


Ondrej Svoboda
Replied On June 21, 2019 12:04 PM UTC

Hi,
I will have same items source for all the rows.

Regards
Ondřej

Shobika Palani [Syncfusion]
Replied On June 24, 2019 04:54 PM UTC

Hi Ondrej, 

Thanks for your update. 

We are currently analyzing the feasibility to achieve your requirement. We will update you with more details on 26th June,2019. 

We will appreciate your patience. 

Regards, 
Shobika. 


Farjana Parveen Ayubb [Syncfusion]
Replied On June 26, 2019 09:34 AM UTC

Hi Ondrej, 
  
Thanks for your patience. 
  
We have analyzed your query to a value to GridMultiColumnDropDownList that is not in underlying collection. You can achieve this requirement by using CustomMultiColumnDropDownControl and CustomMultiColumnDropDownRenderer. Please refer to the below code snippet 
  
this.Grid.CellRenderers.Remove("MultiColumnDropDown"); 
this.Grid.CellRenderers.Add("MultiColumnDropDown"new CustomMultiColumnDropDownRenderer()); 
  
  
public class CustomMultiColumnDropDownRenderer: GridCellMultiColumnDropDownRenderer 
    { 
        protected override SfMultiColumnDropDownControl OnCreateEditUIElement() 
        { 
            return new CustomMultiColumnDropDownControl(this.DataGrid); 
        } 
  
        protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) 
        {            
            if (e.Key == Key.Enter) 
            { 
                var multiDropDown = (this.CurrentCellRendererElement as CustomMultiColumnDropDownControl); 
                multiDropDown.AddItem(multiDropDown); 
            } 
            return base.ShouldGridTryToHandleKeyDown(e); 
        } 
    } 
  
    public class CustomMultiColumnDropDownControl : SfMultiColumnDropDownControl 
    { 
        SfDataGrid DataGrid; 
        public CustomMultiColumnDropDownControl(SfDataGrid dataGrid) : base() 
        { 
            DataGrid = dataGrid; 
        } 
        public override void OnApplyTemplate() 
        { 
            Editor = GetTemplateChild("PART_TextBox"as TextBox; 
            if (Editor != null) 
                Editor.LostFocus += Editor_LostFocus; 
            base.OnApplyTemplate(); 
  
        } 
        private void Editor_LostFocus(object sender, RoutedEventArgs e) 
        { 
            if (!string.IsNullOrEmpty(SearchText)) 
            { 
                AddItem(this); 
            } 
        } 
  
        internal void AddItem(SfMultiColumnDropDownControl multiDropDown) 
        { 
            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 = ((multiDropDown as CustomMultiColumnDropDownControl).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(); 
                } 
            } 
        } 
    } 
  
Please find sample for the same from the link below 
  
Sample Link: 
  
Please let us know, if you require further assistance on this. 
  
Regards, 
Farjana Parveen A. 


Ondrej Svoboda
Replied On June 27, 2019 11:14 AM UTC

Hi,
thanks, I will have a look on it.
In your sample project you have a reference to Syncfusion.SampleLayout - can I get this dll as nuget package like the rest, or I need to install the whole WPF package?

Ondřej

Farjana Parveen Ayubb [Syncfusion]
Replied On June 28, 2019 05:44 AM UTC

Hi Ondrej, 
  
We regret for the inconvenience caused. We have SampleLayout assembly for internal purpose to showcase the samples in SampleBrowser. So we do not publish Nuget package for that assembly. Instead, we have modified the sample provided in our previous update excluding the usage of SampleLayout assembly. Please refer to sample in the link below 
  
Sample Link: 
  
Please let us know, if you require further assistance on this. 
  
Regards, 
Farjana Parveen A 


Ondrej Svoboda
Replied On June 28, 2019 11:10 AM UTC

Hi,
thanks, it is working like I need, except one thing. Please see attached modified sample.

OrderInfo with OrderID = 2 has ProductCode = "bike". But this ProductCode is not in ProductList (deliberately). When you run it empty value is shown in the cell.
Is there a way how to display this value even if it is not in the list?

Thanks

Ondřej


Attachment: GridMultiColumnDropDownDemo94181646_ded3559b.zip

Farjana Parveen Ayubb [Syncfusion]
Replied On July 1, 2019 08:40 AM UTC

Hi Ondrej, 
 
We have analyzed your query to display the value even if it is not in the list on initial loading itself in GridMultiColumnDropDownList. This requirement can be achieved by overriding OnInitializeDisplayElement in CustomMultiColumnDropDownRenderer.  
 
Please refer to the below code snippet 
 
public class CustomMultiColumnDropDownRenderer : GridCellMultiColumnDropDownRenderer 
       { 
              protected override SfMultiColumnDropDownControl OnCreateEditUIElement() 
              { 
                     return newCustomMultiColumnDropDownControl(DataGrid); 
              } 
  
        public override voidOnInitializeDisplayElement(DataColumnBase dataColumn, TextBlock uiElement, object dataContext) 
        { 
            var gridColumn = dataColumn.GridColumn asGridMultiColumnDropDownList; 
            var itemsSource = gridColumn.ItemsSource asObservableCollection<ProductInfo>; 
            var record = dataContext as OrderInfo; 
            if (!(itemsSource.Any(info => info.Code == record.ProductCode))) 
                itemsSource.Add(new ProductInfo() { Code = record.ProductCode }); 
  
            base.OnInitializeDisplayElement(dataColumn, uiElement, dataContext); 
        } 
        protected override boolShouldGridTryToHandleKeyDown(KeyEventArgs e) 
              { 
                     if (e.Key == Key.Enter) 
                     { 
                           var multiDropDown = (CurrentCellRendererElement asCustomMultiColumnDropDownControl); 
                          multiDropDown.AddItem(multiDropDown); 
                     } 
                     returnbase.ShouldGridTryToHandleKeyDown(e); 
              } 
       } 


 
Also please find the modified sample from the link below 
 
Sample Link: 
 
Please let us know, if you require further assistance on this. 
 
Regards,
Farjana Parveen A
 


Ondrej Svoboda
Replied On March 12, 2021 01:55 PM UTC

Hi,
I've found an issue with this solution. Please check little modified sample attached.

In this sample I changed height of the grid so now you need to scroll to see OrderID 7. But when you do so you see empty ProductCode.

If you change the grid height to e.g. 300 and run it again, than there is no scrollbar and you see OrderID 7 with ProductCode bike correctly. 

I thing the problem is that in the first sample OnInitializeDisplayElement is not being executed.

Can you please have a look on this one?

Thanks

Attachment: GridMultiColumnDropDownDemo_Modified1518603693_a52a7792.zip

Mohanram Anbukkarasu [Syncfusion]
Replied On March 15, 2021 02:13 PM UTC

Hi Ondrej,  

Thanks for update.  

We are currently validating this. We will update with further details on March 17, 2021. We appreciate your patience until then.   

Regards,  
Mohanram A. 


Mohanram Anbukkarasu [Syncfusion]
Replied On March 17, 2021 09:42 AM UTC

Hi Ondrej, 

Thanks for your patience.  

We have checked the reported problem in our end. You can resoled this by moving the code changes from OnInitializeDisplayElement to DataGrid.Loaded event as shown in the following code example.  

Code example :  

private void Grid_Loaded(object sender, RoutedEventArgs e) 
{ 
    var itemsSource = (this.Grid.Columns["ProductCode"] as GridMultiColumnDropDownList).ItemsSource as ObservableCollection<ProductInfo>; 
 
    foreach (var item in this.Grid.View.Records) 
    { 
        var record = item.Data as OrderInfo; 
        if (!(itemsSource.Any(info => info.Code == record.ProductCode))) 
            itemsSource.Add(new ProductInfo() { Code = record.ProductCode }); 
    } 
} 

Please find the modified sample from the following link.  


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Ondrej Svoboda
Replied On March 17, 2021 02:17 PM UTC

Hi,
this works only once - if you change grid items during runtime then the last ProductCode is empty again (DataGrid.Loaded is not called of course, see attached sample).
I don't like this solution also because of performance - basically I need to go through all the records first and add missing items to GridMultiColumnDropDownList.ItemsSource.
Solution using OnInitializeDisplayElement event looks the best to me, but why it's not beeing called when scrolling?This seems like a bug to me.

Attachment: GridMultiColumnDropDownDemo_Modified971485032_f02ea24f.zip

Mohanram Anbukkarasu [Syncfusion]
Replied On March 18, 2021 02:11 PM UTC

Hi Ondrej, 

Thanks for the update.   

We are able to reproduce the reported scenario in our end. We currently validating this. We will check and update with further details on March 22, 2021. We appreciate your patience until then.   

Regards,  
Mohanram A. 


Mohanram Anbukkarasu [Syncfusion]
Replied On March 22, 2021 04:23 PM UTC

Hi Ondrej,  

Thanks for the update.    

We are still validating this. We will check and update with further details on March 24, 2021. We appreciate your patience until then.    

Regards,   
Mohanram A. 


Mohanram Anbukkarasu [Syncfusion]
Replied On March 24, 2021 02:09 PM UTC

Hi Ondrej,   

We regret for the inconvenience.    

We are still validating this as it requires more analysis. We will update with further details on March 26, 2021. We appreciate your patience and understanding. 

Regards,    
Mohanram A. 


Mohanram Anbukkarasu [Syncfusion]
Replied On March 26, 2021 06:02 AM UTC

Hi Ondrej, 

Thanks for your patience.  

You can resolve this by overriding InitializeCellStyle in CustomMultiColumnDropDownRenderer as shown in the following code example.  

Code example :  

protected override void InitializeCellStyle(DataColumnBase dataColumn, object record) 
{ 
    base.InitializeCellStyle(dataColumn, record); 
 
    var gridColumn = dataColumn.GridColumn as GridMultiColumnDropDownList; 
    var itemsSource = gridColumn.ItemsSource as ObservableCollection<ProductInfo>; 
    var record1 = record as OrderInfo; 
    if (!(itemsSource.Any(info => info.Code == record1.ProductCode))) 
    { 
        itemsSource.Add(new ProductInfo() { Code = record1.ProductCode }); 
        base.UpdateBindingInfo(dataColumn, record, false); 
    } 
} 


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Ondrej Svoboda
Replied On March 26, 2021 12:15 PM UTC

Hi,
it looks good, thanks.

Mohanram Anbukkarasu [Syncfusion]
Replied On March 29, 2021 05:19 AM UTC

Hi Ondrej, 

Thanks for the update.  

We are glad to know that the provided solution worked at your end. Please let us know if you require any other assistance from us. We are happy to help you.  

Regards, 
Mohanram A. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon