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. General Programming
  3. WCF and WF
  4. Combobox Datatemplate in Code-Behind

Combobox Datatemplate in Code-Behind

Scheduled Pinned Locked Moved WCF and WF
wpfwcfquestion
2 Posts 2 Posters 16 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.
  • A Offline
    A Offline
    aruna_koride
    wrote on last edited by
    #1

    My datatemplate for combobox is as below: <DataTemplate x:Key="Template_ComboBoxItem"> <CheckBox Name="CbName" > <TextBlock Name="tbName" Margin="5,0,5,0" Text="{Binding Name}"/> </CheckBox> </DataTemplate> I want to get the checkBox status(checked or not) from ComboBoxItem for ex: 1 item.. cbi = this.cmbArea.ItemContainerGenerator.ContainerFromItem(entity) as System.Windows.Controls.ComboBoxItem; ContentPresenter contentPresenter = this.FindVisualChild<ContentPresenter>(cbi); contentPresenter.ApplyTemplate(); DataTemplate cellTemplate = this.cmbArea.ItemTemplate; DependencyObject child = VisualTreeHelper.GetChild(contentPresenter, 0); cbName = cellTemplate.FindName("CbName", (FrameworkElement)child) as System.Windows.Controls.CheckBox; The last line throws exception: This operation is valid only on elements that have this template applied. Any mistake???

    L 1 Reply Last reply
    0
    • A aruna_koride

      My datatemplate for combobox is as below: <DataTemplate x:Key="Template_ComboBoxItem"> <CheckBox Name="CbName" > <TextBlock Name="tbName" Margin="5,0,5,0" Text="{Binding Name}"/> </CheckBox> </DataTemplate> I want to get the checkBox status(checked or not) from ComboBoxItem for ex: 1 item.. cbi = this.cmbArea.ItemContainerGenerator.ContainerFromItem(entity) as System.Windows.Controls.ComboBoxItem; ContentPresenter contentPresenter = this.FindVisualChild<ContentPresenter>(cbi); contentPresenter.ApplyTemplate(); DataTemplate cellTemplate = this.cmbArea.ItemTemplate; DependencyObject child = VisualTreeHelper.GetChild(contentPresenter, 0); cbName = cellTemplate.FindName("CbName", (FrameworkElement)child) as System.Windows.Controls.CheckBox; The last line throws exception: This operation is valid only on elements that have this template applied. Any mistake???

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      First, where is the above code running? Which event handler? Second, why not just loop through the Items collection in the ComboBox and check each CheckBox? Then you won't need all that code. Get Mole or Snoop and have a look at your application's Visual Tree so that you can understand what your looping through. It is very easy once you understand this.

      Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

      Just a grain of sand on the worlds beaches.

      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