We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Get the list of SelectedItems, Add New item to Grid, Display Sl No, get edited rows. ReplyClose Incident

Hi,

We are using sfDataGrid for one of our Projects, and we are having below issues. Please suggest the solutions for these, We are using WPF - MVVM. 
Note: BlankSheetList is an ObeservableCollection of Type BlankSheet. SelectedBlankSheet is of type BlankSheet : NotificationObject

1. We are using the Selection mode as Extended. We can get the first selected item as below, which gives the first item in the selected list.
 SelectionMode="Extended"
 SelectedItem="{Binding SelectedBlankSheet, Mode=TwoWay}"   
The Question is, how do we get a List of all the items that are selected? 
Documentation says We can use SelectedItems . But that gives this error - "The Property ''SelectedItems" does not have an accessible setter"

2. We want the users to  be able to add more items to the list, on a button click. However when we try the below code, even though the item gets added to  the collection, it doesn't show up on the grid. We want the item to  show up on the grid, as soon as it gets added to  the collection.
View:
 ItemsSource="{Binding BlankSheetList, Mode=TwoWay}"
ViewModel:
BlankSheetList.Add(theBS);

3. How to display the serial number for each of the item in sfDataGrid?

4. How to  get a list of all the edited rows in the grid and mark it with an "*" in one of the column?

Thanks on advance for the help.
Varalakshmi


1 Reply

SV Srinivasan Vasu Syncfusion Team October 25, 2016 11:01 AM UTC

Hi Varalakshmi 
  
Please find the responses for your queries as below,  
  
               Query  
  
                                           
                               Answer  
How do we get a List of all the items that are selected?  
You can get all the SlectedItems in the grid by using SfDataGrid.SelectedItemsproperty but you cannot set the SelectedItems using this property.  
UG Link:  
  
We want the users to  be able to add more items to the list, on a button click  
You can add the Items at run time by using the below code,  
  
<Button  Content="Click"syncfusion:FocusManagerHelper.FocusedElement="True"    
        Command="{BindingPath=DataContext.RowDataCommand,ElementName=sfGrid}"CommandParameter="{Binding}"/>  
  
  
public void ChangeCanExecute(object obj)  
        {  
            this.UserDetails.Add(new UserInfo() { UserId = 12323, ContactNo = "(833) 215-6503", Name = "Peter", Salary = 12123 });  
        }  
  
  
How to display the serial number for each of the item in SfDataGrid?  
We already have a kb for this and please find the link from below,  
  
How to get a list of all the edited rows in the grid and mark it with an "*" in one of the column?  
You can achieve your requirement by using CurrentCellBeginEdit event like below,  
  
this.AssociatedObject.CurrentCellBeginEdit += AssociatedObject_CurrentCellBeginEdit;  
  
List<UserInfo> list = new List<UserInfo>();  
void AssociatedObject_CurrentCellBeginEdit(object sender,CurrentCellBeginEditEventArgs args)  
{  
    var recordIndex =this.AssociatedObject.ResolveToRecordIndex(args.RowColumnIndex.RowIndex);  
    var record = this.AssociatedObject.View.Records[recordIndex].Data asUserInfo;  
  
    if (!list.Contains(record))  
        list.Add(record);  
  
    record.Status = "*";  
}  
  
  
 
  
  
Regards,  
Srinivasan   
 


Loader.
Live Chat Icon For mobile
Up arrow icon