ComboBox in DataGrid in WPF


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.

ComboBox in DataGrid in WPF_第1张图片

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.

ComboBox in DataGrid in WPF_第2张图片

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

ComboBox in DataGrid in WPF_第3张图片

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:

ComboBox in DataGrid in WPF_第4张图片

...

ComboBoxWPF5.gif

...

ComboBox in DataGrid in WPF_第5张图片

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.

ComboBox in DataGrid in WPF_第6张图片

And when in Edit mode:

ComboBox in DataGrid in WPF_第7张图片

After Updating:

ComboBox in DataGrid in WPF_第8张图片

Hope this article helps.

你可能感兴趣的:(ComboBox in DataGrid in WPF)