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. The killer question

The killer question

Scheduled Pinned Locked Moved WPF
questioncsharpwpfwinformshelp
7 Posts 3 Posters 15 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.
  • E Offline
    E Offline
    Ed Poore
    wrote on last edited by
    #1

    Can the dreaded nullable combo-box be created in WPF. Of course with all the databinding enabled etc? :rolleyes: Seriously, I'm wondering why it hasn't already been done since this was a huge bug-bear with Windows Forms.


    My Blog[^]

    L 1 Reply Last reply
    0
    • E Ed Poore

      Can the dreaded nullable combo-box be created in WPF. Of course with all the databinding enabled etc? :rolleyes: Seriously, I'm wondering why it hasn't already been done since this was a huge bug-bear with Windows Forms.


      My Blog[^]

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

      Ed.Poore wrote:

      Can the dreaded nullable combo-box be created in WPF.

      Ed, Dumb question. What is the dreaded nullable combo-box?

      Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

      Just a grain of sand on the worlds beaches.

      E 1 Reply Last reply
      0
      • L Lost User

        Ed.Poore wrote:

        Can the dreaded nullable combo-box be created in WPF.

        Ed, Dumb question. What is the dreaded nullable combo-box?

        Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

        Just a grain of sand on the worlds beaches.

        E Offline
        E Offline
        Ed Poore
        wrote on last edited by
        #3

        Not a dumb question although a quick Google would have given you the idea. Imagine any field where you want to select an item for a relationship in a drop-down or nothing. E.g. you're assigning a bug to a user in your database. You use LINQ or whatever to pull the users from the database, and these are bound to the combobox so you get a list of all the users. But it should also have (None) or something similar so that if you select that item then the relationship is set to null. There's been no easy workaround this problem in WinForms so hopefully the magic that is WPF would be able to do it :-\


        My Blog[^]

        L 1 Reply Last reply
        0
        • E Ed Poore

          Not a dumb question although a quick Google would have given you the idea. Imagine any field where you want to select an item for a relationship in a drop-down or nothing. E.g. you're assigning a bug to a user in your database. You use LINQ or whatever to pull the users from the database, and these are bound to the combobox so you get a list of all the users. But it should also have (None) or something similar so that if you select that item then the relationship is set to null. There's been no easy workaround this problem in WinForms so hopefully the magic that is WPF would be able to do it :-\


          My Blog[^]

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

          You can add the extra row in the data in your business layer or data layer, or simply extend the combobox to function like the ASP.NET dropdown control that has this built in.

          Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

          Just a grain of sand on the worlds beaches.

          E 1 Reply Last reply
          0
          • L Lost User

            You can add the extra row in the data in your business layer or data layer, or simply extend the combobox to function like the ASP.NET dropdown control that has this built in.

            Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

            Just a grain of sand on the worlds beaches.

            E Offline
            E Offline
            Ed Poore
            wrote on last edited by
            #5

            Karl Shifflett wrote:

            You can add the extra row in the data in your business layer or data layer

            That's those hacks I mentioned. Not really a good design.

            Karl Shifflett wrote:

            extend the combobox to function like the ASP.NET dropdown control that has this built in

            I wanted to see some code ;P


            My Blog[^]

            P 1 Reply Last reply
            0
            • E Ed Poore

              Karl Shifflett wrote:

              You can add the extra row in the data in your business layer or data layer

              That's those hacks I mentioned. Not really a good design.

              Karl Shifflett wrote:

              extend the combobox to function like the ASP.NET dropdown control that has this built in

              I wanted to see some code ;P


              My Blog[^]

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              2 thoughts. 1 - do this in exactly the way that Karl suggested and create your own control, or 2 - use an Extension method that would look something like this:

              public static void NullableDataSource<T>(this ComboBox source, IList<T> binding)
              where T : class, new()
              {
              if (binding != null)
              {
              binding.Insert(0, "<Null>");
              }
              source.DataSource = binding;
              }

              I've not tried this out, I'm just typing the code off the top of my head, but there's no reason that this (or something like this) wouldn't work.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              E 1 Reply Last reply
              0
              • P Pete OHanlon

                2 thoughts. 1 - do this in exactly the way that Karl suggested and create your own control, or 2 - use an Extension method that would look something like this:

                public static void NullableDataSource<T>(this ComboBox source, IList<T> binding)
                where T : class, new()
                {
                if (binding != null)
                {
                binding.Insert(0, "<Null>");
                }
                source.DataSource = binding;
                }

                I've not tried this out, I'm just typing the code off the top of my head, but there's no reason that this (or something like this) wouldn't work.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                E Offline
                E Offline
                Ed Poore
                wrote on last edited by
                #7

                It does work, on the surface. However if you try and access the lists through other methods then it messes up (i.e. through indicies). I was thinking that there'd be an ice elegant way to create a combo box in WPF which allows it to be set as nullable, rather than having to modify the underlying data. Perhaps creating a new items template thingy and inserting a control there which if selected is null. I.e. the underlying datasource is not modified at all. I'll see what I can do when I get the chance. Just wondering if someone had come up with a solution already.


                My Blog[^]

                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