Welcome to MSDN Blogs Sign in | Join | Help

Vincent Sibal's Blog

WPF Programming Topics
WPF DataGrid and the WPFToolKit have released!

Finally, the v1 WPF DataGrid is out!  This is an out-of-band release that will be hosted on the WPF CodePlex site and integrated into the WPF Framework in vNext.  You can download the bits as well as the source code here.  You also may be pleased to hear that included with the WPFToolKit are other controls and features such as DatePicker, Calendar, and VSM!  For any questions/feedback/issues you may have you can post them on the WPF CodePlex discussion list.  Also, be sure to check our Tips & Tricks section on the CodePlex site for more resources and help.

So what’s new in the v1 WPF DataGrid?  Here are some of the features that were not in the CTP:

·         Row Validation

·         Row Details

·         Row Resizing

·         Hidden Columns

·         Column virtualization

·         Read-only columns and cells

·         Make-over of DataGridComboBoxColumn

·         Design experience for the DataGrid in Cider and Blend

·         UIAutomation support

·         Star column width redesign

·         Lots of bug fixes

There is a walkthrough of the feature set on windowsclient.net here and a hands-on lab that you can do here. I have updated the CTP Sample to include the new features.  You can bind to all of the DataGrid and DataGridColumn properties in real-time and I also included samples for DataTable and Linq to SQL scenarios.  You can download the sample here. 

DataGrid_V1_Sample

I also plan to update all my previous posts and samples with the updated bits.  For better organization, I have made additional tags for DataGrid sample and DataGrid concepts.  If you have any feedback or particular samples that you would like to see please let me know.  Stay tuned for addtional material on the DataGrid, VSM, and more. 

Breaking changes and how to update CTP code to v1

1.  Update the xaml namespace from: xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit" To: xmlns:dg=http://schemas.microsoft.com/wpf/2008/toolkit

2.  Update the 'DataFieldBinding' property to 'Binding'

3.  Update DataGridComboBoxColumn.DataFieldBinding to DataGridComboBoxColumn.SelectedItemBinding

4.  Include this namespace in code behind, using Microsoft.Windows.Controls.Primitives;

Posted: Wednesday, October 22, 2008 7:10 AM by vinsibal
Attachment(s): DataGrid_V1_Sample.zip

Comments

Vincent Sibal's Blog said:

UPDATE: the WPF DataGrid v1 has just released. For more information, see this post . The information

# October 29, 2008 9:07 AM

Bong said:

Hi Vincent,

Just replace the CTP Toolkit to v1 in my project and stumbled upon some problems. The CommittingEdit and CancelingEdit events seems to be gone. Were they removed? Or replaced by some other event?

# October 31, 2008 10:29 PM

vinsibal said:

Bong,

Those events have been replaced with CellEditEnding and RowEndEnding.  The args in the event handler will tell you if it is a commit or cancel action.

# November 1, 2008 10:02 AM

Ruler said:

Hi Vincent,

I have a combobox in the datagrid for each row. Depending on the selection of the combobox, i would like to bind the row with different control.

Do you know how i can do that ?

# November 2, 2008 1:39 AM

vinsibal said:

Ruler,

Could you explain a little more on how you want to bind a row to a different control.  Are you not using an ItemsSource then?  Generally rows are bound to data and not other controls.

# November 2, 2008 10:41 AM

Ruler said:

Actually, it's simple.

ON each column, i have a combobox and i would like to bind a textbox with different data in it.

Example,

On each row, i have a combobox with selection of different GPS positions. Then on the next column,

I would like to bind the textbox with the options selected.

# November 2, 2008 7:07 PM

vinsibal said:

Ruler,

Binding a row to a different control is not really what you are asking then.  A row is bound to the data source item.  Each cell is then bound to a property on the data item.  For your scenario, you can binding a property for the comboboxcolumn and the textcolumn to the same property as the comboboxcolumn will end up changing the property on the data source item and the textcolumn is just consuming the same property.  

# November 2, 2008 9:09 PM

Sreeraj said:

Hi Vincent,

     I'm looking for the row validation in datagrid v1. I went through your application and i saw that the row validation is binded with the ValidationHelper like this

<dg:DataGrid.RowValidationRules>

               <local:CustomerValidationRule ValidationStep="UpdatedValue" />

           </dg:DataGrid.RowValidationRules>

. In the ValidationHelper I saw 4 classes inherited from ValidationRule and they contains overrided validate method in which validations is checked.

What i didn't understand is that how these validations are binded with corresponding cells in the row. And also I would like to know how the row tooltip is assigned with the error message.

Thanking you with anticipation,

Sreeraj

# November 3, 2008 4:27 AM

vinsibal said:

Sreeraj,

I wrote two posts on BindingGroups that may be able to help.  Here is the intro post, http://blogs.msdn.com/vinsibal/archive/2008/08/11/wpf-3-5-sp1-feature-bindinggroups-with-item-level-validation.aspx, and here is a post about the validation feedback, http://blogs.msdn.com/vinsibal/archive/2008/09/08/wpf-bindinggroup-and-validation-feedback.aspx.  If you have more questions after that just let me know.

# November 3, 2008 8:40 AM

blindmeis said:

Hi,

I bind the grid to a DataTable. when there more then 20000 rows, grouping becomes veryyyy slow.

any ideas how to make it faster?

# November 4, 2008 5:09 AM

vinsibal said:

blindmeis,

Grouping does not have virtualization built in and therefore is really slow.  You can add virtualization yourself.  Here is a post that points to that, http://blogs.msdn.com/vinsibal/archive/2008/06/12/grouping-and-virtualization.aspx.

# November 4, 2008 8:21 AM

blindmeis said:

Hi Vin,

got he example running, but if i try this in my testapp.

private ReadOnlyObservableCollection<object> BaseGroups

       {

           get

           {

               return base.Groups;

           }

       }

is always null!

if i look into the debug i can see its 40 after setting the groupdescription! i dont know why and when its set to null...

# November 4, 2008 10:14 AM

vinsibal said:

blindmeis,

It's a little tough to tell the issue from just that.  Please email me a zipped repro.  

# November 6, 2008 10:29 AM

Vincent Sibal's Blog said:

The DataGrid walkthrough on windowsclient.net/wpf and the Tips &amp; Tricks section on codeplex talk

# November 7, 2008 10:53 AM

sekhar said:

Hi Vincent,

We have a scenario in one of our applications. we have two dropdownlists in a row in the WPF datagrid. The requirement is that the 2nd dropdownlist should be populated depending on the value that is been selected in the 1st dropdownlist(PK FK relationship exists in the db).Can you please suggest the best way to go forward

# December 5, 2008 1:40 AM

mb said:

Does anyone have idea, how to get string from datagrid and put it into textbox? The command  DataGrid.Cells[x].Rows[y] doesn't work and i couldn't find any other fitting command. It's surelly some obvios solution, but after few hours searching, I haven't found anything.

# December 14, 2008 7:02 AM

vinsibal said:

mb,

You can go through your data source directly.  If you want to go through the DataGrid you can get the item by doing DataGrid.Items[x].  With the Item you have access to all the properties so you can just access it directly from there.  If you really want to use an index on the cell you can do something like this utility code on this thread, http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=34065, and call the GetCell() method.

# December 16, 2008 8:43 AM

vinsibal said:

# December 17, 2008 12:22 PM

Bhuvan said:

I was trying to put a button and an indented text box for displaying self-referential hierarchical data in the data grid.

Trying to do as

<dg:DataGridTemplateColumn Header="Id" >

                               <dg:DataGridTemplateColumn.CellTemplate>

                                   <DataTemplate>

                                       <WrapPanel>

                                           <Button>+</Button>

                                           <ContentPresenter Content="{Binding Indent, Mode=OneTime}" Margin="2,0"/>

                                           <TextBlock Text="{Binding Path=conceptId}"/>

                                       </WrapPanel>                                        

                                   </DataTemplate>

                               </dg:DataGridTemplateColumn.CellTemplate>

                           </dg:DataGridTemplateColumn>

I can see button but not any bound Items. If i bind these columns with regular TextColumn they show up fine.

Any help will be appreciated.

thanks

# March 31, 2009 11:14 AM

vinsibal said:

Bhuvan,

So if you do something like this:

<dg:DataGridTextColumn Binding="{Binding conceptId}" />

it works?  Do you get any binding errors with your TemplateColumn above?

# March 31, 2009 8:02 PM

Wayne said:

I have a DataGridComboBoxColumn bound to a foreign key to another table. The combobox values are then populated from another datasource thus:

<my:DataGridComboBoxColumn Header="Vetted Pos 1" ItemsSource="{Binding Source={StaticResource vetted}}" DisplayMemberPath="DESCRIPTION" SelectedValuePath="CODE" SelectedValueBinding="{Binding VettedPos1, Mode=TwoWay}"/>

When I change the value in the dropdown, the selected index (dg.SelectedIndex) in the code behind is -1.

Any help much appreciated!!

# May 19, 2009 7:10 AM

charley sheng said:

vinsibal,

I have used the datagrid to create the template by using the template column and put customized control into the column. drap visula control into single cell of data grid worked fine, but didn't work for multiple selected cells. any suggestion?

thanks,

charley sheng

# May 20, 2009 5:37 PM

vinsibal said:

Charley,

"drap visula control into a single cell" => "drag visual control into a single cell"?  Could you expand on this a little bit.  I'm not quite sure what you mean.

# May 21, 2009 8:31 AM

Charley sheng said:

Vinsibal,

thank you for yor reply. the DataGrid is used as drop target object and drag some other control, like, button,content tempaltes,... into the datagrid cell or cells. if single cell is slected, the draging is working as expected, but if multiple cells are selected and drag control into the cells, nothing happened. the drag data objects could be seen in the debug but there is not any UI presentation could be seen on the screen.

Best,

charley sheng

# May 21, 2009 10:35 AM

Charley sheng said:

Vinsibal,

I have figured out what the cause is and the problem is fixed.

Best,

charley sheng

# May 29, 2009 12:35 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker