Adding/Removing Columns does not reflected in the view..

Apr 30, 2014 at 11:52 PM
Hi,

I notice the Columns property is of type ObservableCollection.. i.e
public ObservableCollection<DataGridColumn> Columns

but if i add/remove columns after the datagrid is displayed, this is not reflected in the view...

is this as intended?

Cheers,

Fred
Coordinator
May 1, 2014 at 1:49 AM
Edited May 1, 2014 at 1:52 AM
Currently its exposed as observable list but changes will not affect the data grid (we can call it a bug :) ). I never needed this functionality this is why it is not implemented... Ill see if i can enable this feature tomorrow... I think it will not be that easy..
May 1, 2014 at 1:56 AM
Great thx! I was planning on trying to do it my self.. but I don't have a dev environment to build the Toolkit source code..

Fred
Coordinator
May 1, 2014 at 2:08 AM
Why not? I think you can open the solution with VS2013 RC2 and only the supported projects get loaded...
May 1, 2014 at 2:15 AM
i tried.. i have VS2013 / Update 1

but I get the error when i open the MyToolKit.sln for the projects MyToolKit and MyToolkit.Extented.WinRT
The project is targeting frameworks that are either not installed or are included as part of future updates to Visual Studio. See http://go.microsoft.com/fwlink/?LinkID=287985 for more information.

what does it require as a minimum? any idea's?

Fred
Coordinator
May 1, 2014 at 2:26 AM
I migrated the library to a pcl library to support universal apps... You need vs update 2 rc, see http://blogs.msdn.com/b/somasegar/archive/2014/04/02/visual-studio-2013-update-2-rc-universal-projects-for-windows-and-windows-phone.aspx . Its up to you if you want to install a rc. The lib works when using nuget in an older vs installation?
May 1, 2014 at 2:31 AM
I see.. I'll install that and let you know now..

Thx!
May 1, 2014 at 4:06 AM
Yipp.. installing the Update 2 helps :-)
May 1, 2014 at 1:06 PM
Hi rsuter,

i been able to make the required changes, and you datagrid test page still works fine ;-)
The only issue i found with, when/adding removing, the sorting still works.. but the sort indicator no longer get updated..
I'm not sure why..

Shall i send you my changes and you can take it from there?

Fred
Coordinator
May 1, 2014 at 1:10 PM
Did you change a lot? Yes, please send me your solution so that i can see what to do... My email is mail at rsuter.com
May 1, 2014 at 1:24 PM
Not a lot -:) send you a mail..

let me know if you have any questions/issues..

thx!
Coordinator
May 1, 2014 at 3:32 PM
Ok, it is now updated in SVN...

Fixed:
  • Columns can now be changed (add/remove)
  • Added SelectColumn(column, ascending) method
  • Selection is restored when changing sorted column
Please check if it is working for you.
May 2, 2014 at 12:44 AM
Hi,
Yes that look great. The only issue is still that the sort indicator does not show/work correctly.. for you to see the problem do the following using you Sample app..

1) in the DataGridPage, comment out the adding of the columns in a xaml
2) update the OnAddRemovedColumn to add the column, like..

private void OnAddRemovedColumn(object sender, RoutedEventArgs e)
    {
        DataGrid.Columns.Add(new DataGridTextColumn() 
            { Header="Firstname" , Binding= new Windows.UI.Xaml.Data.Binding() { Path = new PropertyPath("Firstname")} });
        DataGrid.Columns.Add(new DataGridTextColumn()
            { Header = "Lastname", Binding = new Windows.UI.Xaml.Data.Binding() { Path = new PropertyPath("Lastname") } });
        DataGrid.Columns.Add(new DataGridTextColumn()
            { Header = "Category", Binding = new Windows.UI.Xaml.Data.Binding() { Path = new PropertyPath("Category") } });

        if (_removedColumn != null)
        {
            DataGrid.Columns.Add(_removedColumn);
            _removedColumn = null; 
        }
    }
now you should see that the sort indicator is not work as expected..

thx
Coordinator
May 2, 2014 at 1:18 AM
Ok, I see. Thats very strange. Any idea?
May 2, 2014 at 1:23 AM
no.. sorry..
Coordinator
May 2, 2014 at 2:14 AM
It seems that when adding a column in XAML the column's dependency properties correctly trigger changes. When adding via code in the Columns collection, they are not correctly triggered. It seems that the Column (which is a DependencyObject) is not correctly registered and thus the DP are not working correctly...
Coordinator
May 2, 2014 at 2:18 AM
If there is at least one column defined in XAML, everything works correctly...
May 2, 2014 at 2:29 AM
mm. i see. it does indeed.. i can work with that! -:)

i also notice you did not include the fix in the UpdateItemsSource to handle the scenario where the items collection is just an array.. like MyClass[]...

private void UpdateItemsSource()
    {
        if (_listControl != null)
        {
            if (ItemsSource != null && !(ItemsSource is IObservableView))
            {
                var types = ItemsSource.GetType().GenericTypeArguments;
                var newList = typeof(ObservableView<>).CreateGenericObject(types.Count() == 0 ? ItemsSource.GetType().GetElementType() : types[0], ItemsSource);
           _listControl.ItemsSource = newList;
            }
            else
                _listControl.ItemsSource = ItemsSource;
        }
    }
thx!
Coordinator
May 2, 2014 at 3:43 AM
Ok, ive fixed it. Its now working even with an empty initial list. I updated UpdateItemsSource too, sorry I missed that. Thanks for your help.
May 2, 2014 at 4:17 AM
great! thx! Work perfect..

you only made a mistake in the UpdareItemsSource.. looks like copy/past issue.. old code is still there, include the new one..

private void UpdateItemsSource()
    {
        if (_listControl != null)
        {
            if (ItemsSource != null && !(ItemsSource is IObservableView))
            {
                var type = ItemsSource.GetType().GenericTypeArguments[0];
                var newList = typeof(ObservableView<>).CreateGenericObject(type, ItemsSource);
                _listControl.ItemsSource = newList;
            }
            else
                _listControl.ItemsSource = ItemsSource;

            if (_listControl != null)
            {
                if (ItemsSource != null && !(ItemsSource is IObservableView))
                {
                    // Wrap original items source with ObservableView for sorting and filtering
                    var types = ItemsSource.GetType().GenericTypeArguments;
                    var observableView = typeof(ObservableView<>).CreateGenericObject(types.Any() ? 
                        types[0] : ItemsSource.GetType().GetElementType(), ItemsSource);

                    _listControl.ItemsSource = observableView; 
                }
                else
                    _listControl.ItemsSource = ItemsSource;
            }

        }
    }
where will you release a new version?

thx!
Coordinator
May 2, 2014 at 4:21 AM
Oh no.. Its too late. Ill fix this and release a new version tomorrow..
May 2, 2014 at 4:23 AM
ok thx!
Coordinator
May 2, 2014 at 7:03 PM
NuGet version 2.2.3 has been released with the updated DataGrid.
Coordinator
May 2, 2014 at 7:04 PM
The list with the new features can be found here:
https://mytoolkit.codeplex.com/releases/view/119422
May 4, 2014 at 7:28 AM
thx!