Add selected GridControl rows to the ObservableCollection

2

I'm trying to add my grid items to my ObservableCollection but I'm unsuccessful. I have a column that has the CheckBox that I put through the ShowCheckBoxSelectorColumn property.

I have the following Xaml:

<dxg:GridControl x:Name="grid" EnableSmartColumnsGeneration="True" AutoGenerateColumns="None"
                     FontWeight="Normal" SelectionMode="MultipleRow" Margin="0,0,0,324" SelectionChanged="grid_SelectionChanged">
        <dxg:GridControl.View>
            <dxg:TableView x:Name="view" ShowGroupPanel="True" AllowEditing="False" ShowTotalSummary="False" AutoWidth="True" NavigationStyle="Row"
                           ShowSearchPanelMode="Never" UseLightweightTemplates="All" FontSize="11" ShowCheckBoxSelectorColumn="True"/>
        </dxg:GridControl.View>
        <dxg:GridControl.Columns>
            <dxg:GridColumn FieldName="Codigo" Header="Código" Width="25"/>
            <dxg:GridColumn FieldName="Descricao" Header="Descrição"/>
        </dxg:GridControl.Columns>

    </dxg:GridControl>

The problem is that I do not know how to add these my selected items to a collection. Can someone help me?

Thank you!

    
asked by anonymous 10.08.2015 / 21:00

1 answer

1

This gets a bit trickier because using DevExpress controls are not the same as the normal XAML controls. But looking at the documentation it looks like it has a property called "SelectedItems" in the GridControl. Then in an event (such as SelectionChanged for example) you can grab the selected items in the "SelectedItems" property and add to the collection by itself. There will not be anything simple that does this automatically. Type, something like this:

public void grid_SelectionChanged(object sender, GridSelectionChangedEventArgs args) 
{
    collection.Clear(); // <-- Seu ObservableCollection
    foreach (var item in grid.SelectedItems) // SelectedItems vem do GridControl (eu acho)
    {
        // Depois de Clear(), adicionar os que são selecionados atualmente
        collection.Add(item); 
    }
}

Documentation: link

    
12.08.2015 / 20:12