ARTICLE

ComboBox in DataGrid in WPF

Posted by Diptimaya Patra Articles | WPF February 18, 2010
This article will describe the DataGrid in Edit mode while the edit cell requires a list of data.
Reader Level:
Download Files:
 

Introduction

This article will describe the DataGrid in Edit mode while the edit cell requires a list of data. We are going to achieve that using the ComboBox.

Crating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as DatePickerDGWPF.

ComboBoxWPF1.gif

Here is the basic idea of our sample application; we would have sample data with one property that can be selected from a list of values displayed in ComboBox.

When the particular cell will be edit mode, we would be able to select from the list displayed in the ComboBox.

So let's have a class and have sample data.

ComboBoxWPF2.gif

Now we will add a DataGrid to the Window and design the Columns inside of it.

ComboBoxWPF3.gif

We need to set the ItemSource Property; for that I have created a Class that would generate the list and in XAML I have accessed it and assigned it. The following figures will clarify what I have done:

ComboBoxWPF4.gif

...

ComboBoxWPF5.gif

...

ComboBoxWPF6.gif

It seems we are done with the design of our DataGrid columns.

Run the application and try to edit the column "Status", you would get ComboBox control to handle the Status List.

ComboBoxWPF7.gif

And when in Edit mode:

ComboBoxWPF8.gif

After Updating:

ComboBoxWPF9.gif

Hope this article helps.

Login to add your contents and source code to this article
post comment
     

Great work. can you tell me how to store "value" and "item" in ComboBox. (To get Different arguments as "SelectedValue" and "SelectedItem")

Posted by Sandun Dhanushka May 09, 2013

really helpfull, but I want to open the combo when we write into that "Status" cell. For example when I add a new row and after adding subject, as I enter a letter in "Status" cell this combo should open. Plz tell me If we can achieve this one also.

Posted by Ratnesh Khandelwal Apr 25, 2013

Great. Simple example and very clear. Thanks.

Posted by Jay Hamlin Jan 22, 2013

Thanks for sharing! it is helpful for me !Thanks again!

Posted by fang Sterling Nov 19, 2012

This is the first article i've read about this control that actually gives propper explaination of how it should work. Thank you sir.

Posted by emmett maguire Oct 31, 2012
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts