how can I ask if grid.selectedvalue is newitemplaceholder in wpf

Asier 41 Reputation points
2021-11-22T11:43:00.327+00:00

I am trying to add new record to database by linq only if is a new row from a datagrid wpf.

151494-sin-titulo.png

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,678 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2021-11-22T12:08:09.687+00:00

    You could use is. Here is a sample example

    public interface IItemType  
    {  
        int x { get; set; }  
    }  
    
    
    public class OldItem : IItemType  
    {  
        public int x { get; set; }  
    }  
    
    
    public class NewItem : IItemType  
    {  
        public int x { get; set; }  
    }  
    
    
       for(int i=0; i<10;i++)  
       {  
           if(i % 2 ==0)  
           {  
               list.Add(new OldItem { x = i });  
           }  
           else  
           {  
               list.Add(new NewItem { x = i });  
           }  
       }  
    
       var newItems = list.Where(itm => itm is NewItem).ToList();  
    

    https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/is

    0 comments No comments