How to loop over the rows of a WPF toolkit Datagrid

前端 未结 4 1056
情歌与酒
情歌与酒 2020-11-30 15:04

I have the next code where I defined a WPF toolkit datagrid control called dgQuery; I filled this one with information of a dataset, then I inserted a new checkbox column in

4条回答
  •  情深已故
    2020-11-30 15:54

    Not sure if this is helpful because it assumes a different approach than what you started with, but rather than working directly with the grid, you could bind it to an ObservableCollection of objects that have properties for each column. If you add a bool property in your object for "Selected" and bind the checkbox column to it, you can then query the collection at any time for what is currently selected, like this:

     List selectedItems = 
                new List(from memberEntity in _memberEntities 
                                       where memberEntity.Selected == true 
                                       select memberEntity);
    
            //now save selectedItems to the database...
    

    So MemberEntity is a class that has a property for each of the columns in your grid, including a bool called Selected for the checkbox column. _memberEntities is an ObservableCollection of MemberEntity instances. The grid's ItemSource property is bound to _memberEntities and each of its column's Binding properties are bound to a property in MemberEntity like this, assuming that Selected and Name are properties in MemberEntity:

    
            
                
                
            
    
    

提交回复
热议问题