Home Forums WPF controls Xceed DataGrid for WPF Deleting from LINQ Table

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

    Hello !!

    I have a DataGridControl bound to a LINQ table and i’ve tried to delete delete records from that source using the code from the samples provided with the product, but when the code reachs the line

    DataView dataView = ((DataGridCollectionView)grid.ItemsSource).SourceCollection as DataView;

    it returns null as thevalue of ‘dataView’.

    ¿ What’s the matter with it ?

    thanks!

    Imported from legacy forums. Posted by Miguel (had 4942 views)

    Xceed Support
    Member
    Post count: 5658

    Most likely that the type of the ItemsSource is not a DataView. I suggest you put a break point on that line and check the type of the SourceCollection in order to cast it to the appropriate type.

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

    User (Old forums)
    Member
    Post count: 23064

    Hello !!

    The type of the source collection is “{Name = “DataBindingList`1” FullName = “System.Data.Linq.Provider.DataBindingList`1[[ComunidadBM_WPF.Contadore, ComunidadBM_WPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]”}

    The grid is bound to a LINQ table named ‘Contadores’ of type ‘Contadore’. The variable used to store the LINQ data context is named ‘LinqDataContext’.

    Following is the code that i’ve used instead of the code shown in the sample that uses a DataTable to fill the DataGridCollectionView.Source:

    ————————————-

    private void DeleteSelectedRows( object sender, KeyEventArgs e )
    {
    DataGridControl grid = sender as DataGridControl;
    if( grid != null )
    {
    if( e.Key == Key.Delete )
    {
    if( grid.SelectedItems.Count > 0 )
    {
    LinqDataContext.Contadores.DeleteAllOnSubmit(this.grid.SelectedItems.Cast<Contadore>());
    LinqDataContext.SubmitChanges();
    ((DataGridCollectionView)grid.ItemsSource).Refresh();
    grid.CurrentItem = grid.Items[ 0 ];
    }
    }
    }
    }

    —————————————–

    But…there is an issue with this code:

    * The deleted items remains in the grid until close and open the application again.

    ¿ What am i doing wrong ?
    ¿ Please, Can you show me an example to delete items from a LINQ table that refreshes the grid without the needing of reboot the application ?

    Thanks !!

    Imported from legacy forums. Posted by Miguel (had 594 views)

    Xceed Support
    Member
    Post count: 5658

    The Linq.Table does not implement change notification, therefore, there is no way for the grid to know that its collection has changed. That said, bind the grid to the BindingList returned by GetNewBindingList and use the Remove method.

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

    User (Old forums)
    Member
    Post count: 23064

    Hello !!

    Sorry, but i’m new to xaml and i would like to do this through xaml code. So…could you show me an example to bind my DataGridCollectionViewSource to the GetNEwBindingList using xaml ?

    Thanks!!

    Imported from legacy forums. Posted by Miguel (had 493 views)

    Xceed Support
    Member
    Post count: 5658

    You will need to create a property that returns the new BindingList and bind the DataGridCollectionViewSource to that property.

    <code>
    private static IBindingList m_linqDataContextCache = null;
    public static IBindingList LinqDataContext2
    {
    get
    {
    if( m_linqDataContext == null )
    m_linqDataContext = new NorthwindDataContext();

    if( m_linqDataContextCache == null )
    m_linqDataContextCache = m_linqDataContext.DiscontinuedProductsFedarateds.GetNewBindingList();

    return m_linqDataContextCache;
    }
    }

    <xcdg:DataGridCollectionViewSource x:Key=”cvs_orders”
    Source=”{Binding Source={x:Static Application.Current},
    Path=LinqDataContext2}” />
    </code>

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks … that works fine, but now i have a problem:

    I use a ComboBox custom cell editor like those used in the DataBinding samle for many columns in my grid.

    If the BindingList attached to the ItemsSource property of the ComboBox has a lot of elements, when i try to open the combo, it takes a lot of time to show all the elements, and the same happens when i close the combo and try to navigate to another cell or row in the grid.

    Here is my code:
    ————————————————————————————–

    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_RepartoDirecto” Source=”{Binding Source={x:Static Application.Current}, Path=ListaRepartoDirecto}” Filter=”DataGridCollectionViewSource_Filter”/>

    <DataTemplate x:Key=”bajanteDataTemplate”>
    <TextBlock Text=”{Binding NombreBajante}”
    TextTrimming=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextTrimming}”
    TextWrapping=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextWrapping}”/>
    </DataTemplate>

    <xcdg:CellEditor x:Key=”bajanteEditor”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <ComboBox ItemsSource=”{Binding Source={x:Static Application.Current}, Path=LinqDataContext.Bajantes}” SelectedValue=”{xcdg:CellEditorBinding}” SelectedValuePath=”IdBajante” ItemTemplate=”{StaticResource bajanteDataTemplate}”/>
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    </xcdg:CellEditor>
    </Grid.Resources>

    <xcdg:DataGridControl x:Name=”gridRepartosDirectos” ValidationMode=”CellEndingEdit” CellEditorDisplayConditions=”CellIsCurrent” HorizontalAlignment=”Stretch” VerticalAlignment=”Stretch” ItemsSource=”{Binding Source={StaticResource cvs_RepartoDirecto}}” Grid.Row=”0″ PropertyChanged=”gridRepartosDirectos_PropertyChanged”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”IdSocio” Title=”Socio” />
    <xcdg:Column FieldName=”IdBajante” TextTrimming=”None” Title=”Bajante” CellEditor=”{StaticResource bajanteEditor}”/>
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
    ————————————————————————————–

    So my question is…

    ¿ How can i accelerate the open/close behavior of the ComboBox ?

    Thanks in advance !!

    Imported from legacy forums. Posted by Miguel (had 1303 views)

    User (Old forums)
    Member
    Post count: 23064

    One more thing….

    When I close the window while the combobox is still open, it takes a lot of time too.

    thanks!!

    Imported from legacy forums. Posted by Miguel (had 8011 views)

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