Condividi tramite


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=https://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;

DataGrid_V1_Sample.zip

Comments

  • Anonymous
    October 29, 2008
    UPDATE: the WPF DataGrid v1 has just released. For more information, see this post . The information

  • Anonymous
    October 31, 2008
    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?

  • Anonymous
    November 01, 2008
    The comment has been removed

  • Anonymous
    November 01, 2008
    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 ?

  • Anonymous
    November 02, 2008
    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.

  • Anonymous
    November 02, 2008
    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.

  • Anonymous
    November 02, 2008
    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.  

  • Anonymous
    November 02, 2008
    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

  • Anonymous
    November 03, 2008
    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.

  • Anonymous
    November 03, 2008
    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?

  • Anonymous
    November 04, 2008
    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.

  • Anonymous
    November 04, 2008
    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...

  • Anonymous
    November 06, 2008
    blindmeis, It's a little tough to tell the issue from just that.  Please email me a zipped repro.  

  • Anonymous
    November 07, 2008
    The comment has been removed

  • Anonymous
    December 04, 2008
    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

  • Anonymous
    December 13, 2008
    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.

  • Anonymous
    December 16, 2008
    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.

  • Anonymous
    December 17, 2008
    sekhar, I just wrote a new post that might help you out, http://msdn.technetweb3.orcsweb.com/vinsibal/archive/2008/12/17/wpf-datagrid-dynamically-updating-datagridcomboboxcolumn.aspx.

  • Anonymous
    March 31, 2009
    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

  • Anonymous
    March 31, 2009
    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?

  • Anonymous
    May 18, 2009
    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!!

  • Anonymous
    May 20, 2009
    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

  • Anonymous
    May 21, 2009
    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.

  • Anonymous
    May 21, 2009
    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

  • Anonymous
    May 29, 2009
    Vinsibal, I have figured out what the cause is and the problem is fixed. Best, charley sheng

  • Anonymous
    March 06, 2010
    Is there an example showing how to have nested dataGrids (e.g. have a master DataGrid with 2 columns, but I want o have each row to be expanded to show another data grid .

  • Anonymous
    March 11, 2010
    AJJohn123, You can nest a DataGrid in the RowDetailsTemplate.  When you select a row it should display that nested DataGrid.

  • Anonymous
    April 01, 2010
    AutoGenerateColumns="True" doesn't work for public IEnumerable<ClientAudit> Audit where ClientAudit is an entity in LINQ to SQL. When I bind columns manually it works, but I have like 100 tables, and thought it would be nice to just drop a data grid and it will find columns automatically.

  • Anonymous
    April 01, 2010
    AutoGenerateColumns="True" does work with POCO classes though. So I am confused why it's not working. Here is XAML                    <wpfToolkit:DataGrid                        VirtualizingStackPanel.VirtualizationMode="Recycling"                        ItemsSource="{Binding Path=Audit, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"                        SelectionMode="Single"                        AutoGenerateColumns="True"                        VerticalAlignment="Stretch"                        HorizontalAlignment="Stretch"                        CanUserAddRows="False"                        CanUserDeleteRows="False"                        Background="Transparent"                        RowBackground="Transparent"                        Foreground="DarkBlue"                        GridLinesVisibility="None"                        AlternatingRowBackground="{StaticResource HorizontalBrush}"                        RowHeaderWidth="0"                        ColumnHeaderStyle="{StaticResource dgHeaderStyle}"                        >