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. WPF
  4. WPF DatagridComboBoxColumn - puzzler

WPF DatagridComboBoxColumn - puzzler

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpwcf
4 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.
  • D Offline
    D Offline
    Duke Carey
    wrote on last edited by
    #1

    Kind of a newbie question. In my XAML I have these 2 lines

    The first one WILL NOT display the value but the second one will. I created the second line to test my sanity [and the binding]. In the viewmodel I've exposed a

    List

    that I had initially bound to the combobox column's ItemsSource. However, when the column failed to display any data I removed it to see if that made a difference. With the List bound to the ItemsSource there was no value for the bound ExpenseCategory property and nothing in the list of values. That XAML was simply:

    So...what am I missing here? Why won't the combobox column display my data?

    D 1 Reply Last reply
    0
    • D Duke Carey

      Kind of a newbie question. In my XAML I have these 2 lines

      The first one WILL NOT display the value but the second one will. I created the second line to test my sanity [and the binding]. In the viewmodel I've exposed a

      List

      that I had initially bound to the combobox column's ItemsSource. However, when the column failed to display any data I removed it to see if that made a difference. With the List bound to the ItemsSource there was no value for the bound ExpenseCategory property and nothing in the list of values. That XAML was simply:

      So...what am I missing here? Why won't the combobox column display my data?

      D Offline
      D Offline
      Duke Carey
      wrote on last edited by
      #2

      FWIW - and I have no idea if this is even close to an optimal approach - I found this solution in an old article by Julie Lerman http://msdn.microsoft.com/en-us/magazine/gg983481.aspx[^]

      In her article she explains that the Grid FocusManager is used to manage the events when a new row is created and the user's first click is in the combobox. This approach seems to work OK, but it is far from straightforward and I hope that somebody here has a better solution that would allow the DataGridComboboxColumn to work for me.

      Richard DeemingR 1 Reply Last reply
      0
      • D Duke Carey

        FWIW - and I have no idea if this is even close to an optimal approach - I found this solution in an old article by Julie Lerman http://msdn.microsoft.com/en-us/magazine/gg983481.aspx[^]

        In her article she explains that the Grid FocusManager is used to manage the events when a new row is created and the user's first click is in the combobox. This approach seems to work OK, but it is far from straightforward and I hope that somebody here has a better solution that would allow the DataGridComboboxColumn to work for me.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        How about combining the two approaches? Since you've already managed to get the viewmodel into a static resource, something like this should work:

        <DataGridComboBoxColumn
        SelectedItemBinding="{Binding ExpenseCategory}"
        ItemsSource="{Binding ExpTypes, Source={StaticResource vm}}"
        Header="Category"
        />


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        D 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          How about combining the two approaches? Since you've already managed to get the viewmodel into a static resource, something like this should work:

          <DataGridComboBoxColumn
          SelectedItemBinding="{Binding ExpenseCategory}"
          ItemsSource="{Binding ExpTypes, Source={StaticResource vm}}"
          Header="Category"
          />


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          D Offline
          D Offline
          Duke Carey
          wrote on last edited by
          #4

          Thanks for the reply. I've been crawling my way towards that solution by incrementally melding some of the elements of Julie Lerman's approach with a DataGridComboBoxColumn, just hadn't gotten all the way to the one you've suggested. However, I've just tried your code and it works. Much more concise. Probably should have mentioned in the original question that I'd taken the [non-working] syntax directly from MSDN's latest example for combo box columns, and that had me flummoxed.

          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