0

Hi i have a Combo box control in my page the data for the combo box are generated using IEnumerable collection from view model. now i want to add a static string at the last of the combo box items. how to do this? i have attached an screen shot of my combo box it has 4 values now i want add a string example

"Custom Size" at the bottom of the items. i have attached my view model code also.enter image description here

    PartsDomainContext context;
    private IEnumerable<CategoryHierarchy> Categoryhierarchies;
    private IEnumerable<CategoryHierarchy> _SizeCategoryhierarchies;
    private CategoryHierarchy categoryhierarchy;
    private CategoryHierarchy _Sizecategoryhierarchy;
    private ProductCategory productcategory;


    public IEnumerable<CategoryHierarchy> SizeCategoryHierarchies
    {
        get
        {
            return _SizeCategoryhierarchies;
        }
        set
        {
            _SizeCategoryhierarchies = value;

        }
    }


    public CategoryHierarchy SizeCategoryHierarchy
    {

        get { return _Sizecategoryhierarchy; }

        set
        {

            if (_Sizecategoryhierarchy == null)
            {

                _Sizecategoryhierarchy = value;
                OnPropertyChanged("SizeCategoryHierarchy");

                ActiveData.Instance.size = _Sizecategoryhierarchy.Category.CategoryName.ToString();
                ActiveData.Instance.Description1 = _Sizecategoryhierarchy.Category.Description1;
                ActiveData.Instance.Description2 = _Sizecategoryhierarchy.Category.Description2;
                ActiveData.Instance.ShortDescription1 = _Sizecategoryhierarchy.Category.ShortDescription1;
                ActiveData.Instance.Notes = _Sizecategoryhierarchy.Category.Notes;

            }
            else
            {
                try
                {
                    _Sizecategoryhierarchy = value;
                    OnPropertyChanged("SizeCategoryHierarchy");

                    ActiveData.Instance.size = _Sizecategoryhierarchy.Category.ToString();
                }
                catch (Exception ex)
                {
                }
                finally
                {
                }
            }




        }


    }



    public Wizard1ViewModel()
    {
        GetSize();
    }


    public void GetSize(int parentcategory)
    {
        context = new PartsDomainContext();
        IsBusy = true;
        context.Load(context.GetCategoryByHierarchyQuery(1), e =>
        {
            if (!e.HasError)
            {

                SizeCategoryHierarchies = e.Entities.Where(c =>       c.ParentCategory.Equals(parentcategory));

                OnPropertyChanged("SizeCategoryHierarchies");

                IsBusy = false;

            }
        }, null);
    }


//Xaml 

        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.RowDefinitions>
                <RowDefinition Height="0*" />
                <RowDefinition Height="300*" />
            </Grid.RowDefinitions>


                    <ComboBox Name="poolsize" ItemsSource="{Binding SizeCategoryHierarchies, Mode=TwoWay}" DisplayMemberPath="Category.CategoryName" SelectedValuePath="Category.CategoryName" SelectedItem="{Binding SizeCategoryHierarchy, Mode=TwoWay}" HorizontalAlignment="Left" Margin="132,0,0,82" FontSize="16" VerticalAlignment="Bottom"  Width="216" RenderTransformOrigin="0.505,2.967" DropDownOpened="poolsize_DropDownOpened_1"/>




        </Grid>
Venkatesh
  • 37
  • 4

1 Answers1

2

As IEnumerable doesn't provide Add method but You can use Concat on your INumerable and you can find the detailed answer at the following link How can I add an item to a IEnumerable<T> collection?.

Regards,

Community
  • 1
  • 1
Learning Curve
  • 1,449
  • 7
  • 30
  • 60