Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. WPF cascaded combo

WPF cascaded combo

Scheduled Pinned Locked Moved Database
wpfcsharpdatabasecsswcf
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bindum31
    wrote on last edited by
    #1

    Hi, I am using LINQ to SQL and MVVM pattern in my application where i am retrieving my data by the following query:

    internal ObservableCollection<INVCategory> GetCategoryList()
    {
    DataLoadOptions dataLoadOptions = new DataLoadOptions();
    dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
    this.Context.LoadOptions = dataLoadOptions;

      var categories = from category in this.Context.INVCategories
                       orderby category.CatgeoryId descending
                       select category;
      return new   ObservableCollection&lt;INVCategory&gt;(categories.ToList());
    

    }

    And my XAML code for parent(Category) combo is:

    <ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox" ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName" SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}">
    </ComboBox>

    for child(Subcategory) combo i am using:

    <ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1" ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}" DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId" SelectedItem="{Binding INVSubCategories, Mode=TwoWay}" >
    </ComboBox>

    But my child combo items is not populated during form loading as well as parent combo's selection changed though my parent combo items are populated. i can't figure out why my child combo is not functioning based on parent combo's selected item ,please help me.

    M 2 Replies Last reply
    0
    • B bindum31

      Hi, I am using LINQ to SQL and MVVM pattern in my application where i am retrieving my data by the following query:

      internal ObservableCollection<INVCategory> GetCategoryList()
      {
      DataLoadOptions dataLoadOptions = new DataLoadOptions();
      dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
      this.Context.LoadOptions = dataLoadOptions;

        var categories = from category in this.Context.INVCategories
                         orderby category.CatgeoryId descending
                         select category;
        return new   ObservableCollection&lt;INVCategory&gt;(categories.ToList());
      

      }

      And my XAML code for parent(Category) combo is:

      <ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox" ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName" SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}">
      </ComboBox>

      for child(Subcategory) combo i am using:

      <ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1" ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}" DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId" SelectedItem="{Binding INVSubCategories, Mode=TwoWay}" >
      </ComboBox>

      But my child combo items is not populated during form loading as well as parent combo's selection changed though my parent combo items are populated. i can't figure out why my child combo is not functioning based on parent combo's selected item ,please help me.

      M Offline
      M Offline
      Michael J Eber
      wrote on last edited by
      #2

      I think you are more likely to get an answer posting this on the WPF forum instead of the SQL forum. But I experienced basically the same thing and finally wrote my own code the old-fashioned way to populate the child table. Though, looking at your XAML you've pretty much setup a logical binding between the two. Good luck.

      1 Reply Last reply
      0
      • B bindum31

        Hi, I am using LINQ to SQL and MVVM pattern in my application where i am retrieving my data by the following query:

        internal ObservableCollection<INVCategory> GetCategoryList()
        {
        DataLoadOptions dataLoadOptions = new DataLoadOptions();
        dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
        this.Context.LoadOptions = dataLoadOptions;

          var categories = from category in this.Context.INVCategories
                           orderby category.CatgeoryId descending
                           select category;
          return new   ObservableCollection&lt;INVCategory&gt;(categories.ToList());
        

        }

        And my XAML code for parent(Category) combo is:

        <ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox" ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName" SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}">
        </ComboBox>

        for child(Subcategory) combo i am using:

        <ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1" ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}" DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId" SelectedItem="{Binding INVSubCategories, Mode=TwoWay}" >
        </ComboBox>

        But my child combo items is not populated during form loading as well as parent combo's selection changed though my parent combo items are populated. i can't figure out why my child combo is not functioning based on parent combo's selected item ,please help me.

        M Offline
        M Offline
        Michael J Eber
        wrote on last edited by
        #3

        I was sitting out on my porch having lunch when I realized what your problem may be. I remember there was a property (don't know it right now .. you'll have to search for the obvious in your XAML) which was basically binding to an event to tell the control when to rebind it's data. You need to find that property and bind it to the combobox SelectionChanged event.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups