Home Forums WPF controls Xceed DataGrid for WPF AutoCreateColumns false, but no columns

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23288 |

    Hi,

    I’ve set AutoCreateColumns to false, and defined some columns, but my grid is empty. When I remove the cols and set AutoCreateColumns to true, the grid populates fine. The FieldNames are correct.

    <xcdg:DataGridControl x:Name=”grid” AutoCreateColumns=”False”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”Lines” Title=”Lines” VisiblePosition=”0″/>
    <xcdg:Column FieldName=”SuburbLocality” Title=”Suburb” VisiblePosition=”1″/>
    <xcdg:Column FieldName=”StateProvince” Title=”State” VisiblePosition=”2″/>
    <xcdg:Column FieldName=”Country” Title=”Country” VisiblePosition=”3″/>
    <xcdg:Column FieldName=”PostcodeZip” Title=”Postcode” VisiblePosition=”4″/>
    </xcdg:DataGridControl.Columns>

    <xcdg:DataGridControl.View>
    <xcdg:TableView Theme=”{DynamicResource defaultTheme}”/>
    </xcdg:DataGridControl.View>
    </xcdg:DataGridControl>

    any thoughts? Sorry for a potentially lame question, I’ve only just started to look into this grid.

    thanks

    Imported from legacy forums. Posted by Jack (had 3478 views)

    Xceed Support
    Member
    Post count: 5658

    Setting the DisplayMemberBinding property of each column to the name of the field in the datasource from which you want to retrieve the values should fix the issue.

    When binding the grid to a DataGridCollectionView or DataGridCollectionViewSource (in XAML), it is recommended to use the ItemProperties property to add or remove the columns the will end up in the Columns collection and leave the AutoCreateColumns property to true.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 309 views)

    User (Old forums)
    Member
    Post count: 23064

    Could you please clarify something for me?

    In your first sentence it looks like you say (if my interpretation is correct); Use XAML as per my code sample above but also set the DisplayMemberBinding

    and in your 2nd sentence you say;

    set ItemProperties in the DataGridCollectionView to control which columns are rendered.

    Do I have to do BOTH of these, or is one enough?

    I tried this;

    DataGridCollectionView dataGridCollectionView = new DataGridCollectionView(myCollection);
    DataGridItemProperty temp1 = new DataGridItemProperty(“AddressID”, “AddressID”, typeof(Guid));
    DataGridItemProperty temp2 = new DataGridItemProperty(“Lines”, “Lines”, typeof(string));

    dataGridCollectionView.ItemProperties.Add(temp1);
    dataGridCollectionView.ItemProperties.Add(temp2);

    grid.ItemsSource = dataGridCollectionView;

    and set AutoCreateColumns=true, but the output was ALL of the properties in each collection object, not just the above 2.

    thanks

    Imported from legacy forums. Posted by Jack (had 294 views)

    Xceed Support
    Member
    Post count: 5658

    Sorry for the confusion. They are 2 different ways of working with the grid.

    If you set the AutoCreateColumns property to false (assuming you are not using the DataGridCollectionView) then setting the DisplayMemberBinding property for each column should fix your issue.

    If your grid is bound to a DataGridCollectionView (recommended), then you should leave the AutoCreateColumns property to true and manage the columns through the ItemProperties collection. Each item that is contained in this collection represents a column in the grid. Try clearing the ItemProperties collection before adding the new ItemProperties, this should limit the columns to only the ones you specify.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 806 views)

    User (Old forums)
    Member
    Post count: 23064

    hi jenny

    thanks for that.

    I did have to clear first;

    dataGridCollectionView.ItemProperties.Clear();

    and it all works now.. so far 😉

    full code;
    DataGridCollectionView dataGridCollectionView = new DataGridCollectionView(myCollection);
    DataGridItemProperty temp1 = new DataGridItemProperty(“SuburbLocality”, “SuburbLocality”, typeof(string));
    DataGridItemProperty temp2 = new DataGridItemProperty(“Lines”, “Lines”, typeof(string));

    dataGridCollectionView.ItemProperties.Clear();
    dataGridCollectionView.ItemProperties.Add(temp1);
    dataGridCollectionView.ItemProperties.Add(temp2);

    grid.ItemsSource = dataGridCollectionView;

    Imported from legacy forums. Posted by Jack (had 4518 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.