One of the question which was asked on the silverlight forum was how to delete multiple rows of the datagrid when you have provided the checkboxs in the datagrid for the selection of more then one row in the datagrid.
The solution to this problem is very simple and as I have not perform such functionality like that to delete records based on the number of selected records in the datagrid. I do perform such functionality in the asp.net grid but not in the silverlight datagrid. The output can be seen in the Image 1, here you can see that I have button control with content as "Delete" this button is used to remove the selected records and one datagrid control which display the record and each record has the checkbox control which is used for multiple selection to delete.
The xaml code for the sample application is shown in the List 1, here you can see that button control is placed inside the stack panel layout which is placed in the first row of the grid layout. Then in the second row is the datagrid control which has number of columns binds to the properties which are displayed to the user here you can see that I have used DataGridTemplateColumn for the first column which is used to have checkbox control so the selection of the row and the checkbox control is bind to the IsSelected property with mode TtwoWay.
The code behind part which is used to remove the records from the datagrid is shown in the List 2, here you can see that I have selected the records which has the IsSelected property to true from the customerList which is declared at class level and bind to the ItemsSource of the datagrid control in the Loaded event of the page.
Here in the List 2 you can first I have search for the selected records of the datagrid which user has selected for the delete after selecting the record I have use foreach loop to remove item one by by from my customerList which is bind to the datagrid control and has the original records which ware fetched from the database. I have just simply use the Remove function of the Observable collection if you are using web service then you have to either pass the list of selected records or need to pass the selected items Ids and then on the completed event of your remove/delete web service method you can remove it locally or need to fetch record by calling web service method.You can download the source code from here.
All and any comments / bugs / suggestions are welcomed!