DataGrid in ComboBox

We all know how to use the ComboBox, bind it to a collection and set DisplayMemberPath and we are done

we get a nice looking ComboBox

we can make it look like this with few tweaks (yes, DataGrid with all the functionality in the popup)

Download the code here

if you did not already leave the site, I am still looking for a job either in WPF or Silverlight, please let me know


20 thoughts on “DataGrid in ComboBox

  1. Hey Lee,
    Got any clues for creating a true ComboBox in which the items can be editabled? Maybe a ComboBox that can host a TextBox AND a DropDownList so that you could enter a name (ad hoc) into the combobox or select from the lists in the ItemSource.

    I’m working on this now. Thought I might ping you to see if you got any ideas.

    Great site, man.


  2. I am waiting for the release version. if the feature is not there in the release version. then I might take a shot at it. I would say we have to inherit from the ComboBox and change the template.

  3. Can you help me how to make the combobox editable when combobox has DataGrid.I want to Edit the
    Combobox so that i can
    add new item by editing in the combobox instead of
    going to the last row in the DataGrid if my DataGrid Contains so many items.

      1. Hi Lee,

        Thanks for the good work.

        I have a DataGrid with three columns of data in my combobox.
        I want to select a row form DataGrid. and it should appear as selected item on Combobox.

        ny idea how it is done…!!!

        Thank you

    1. Lee,

      Could you make this work with data loading from Web Service using LINQ to SQL Classes?

      I am having error on the line
      popup = (visualTreeHelper.GetChild…..
      during runtime.
      NullReferenceException was unhandled by user code.

      I ma new to C#.

  4. Lee,

    I was amazed to find this as it was exactly what I need, unfortunately it does not work in silverlight 4 anymore and simply throws a number of errors.

    As it is way beyond my ken at present to even understand how this all works, I don’t suppose you can post an update for version 4?

  5. How can i customize the Datagrid inside your “MyComboBox”?
    I mean, in your example code cb1.ItemSource = People, when click ComboBox , i dont want to display all 3 Collums “FirstName”,”LastName”,”HomeTown”. I only want to Chose “FirstName” and “LastName” to Display on dataGrid and can change TitleHeader. How can i do?
    I thank for your sharings!!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s