Referring to my previous Question : DataGrid itemsSource from Joined Tables in SQL Database using LINQ
i create this data Grid :
<DataGrid x:Name="DataGridRegisteredUsers" IsReadOnly="True" AutoGenerateColumns="False"
HorizontalContentAlignment="Stretch" Margin="0,0,-1,-1"
FlowDirection="RightToLeft" Opacity="0.9" FontFamily="B Nazanin" FontSize="15" RowDetailsVisibilityMode="Visible">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=UserID}" IsReadOnly="True"
Header="UserID" />
<DataGridTextColumn Binding="{Binding Path=FirstName}"
Header="First Name" />
<DataGridTextColumn Binding="{Binding Path=LastName}"
Header="Last Name" />
<DataGridTextColumn Binding="{Binding Path=EmploymentID}"
Header="Employment ID" />
<DataGridTextColumn Binding="{Binding Path=Status}"
Header="Status" />
</DataGrid.Columns>
</DataGrid>
but now i need to collect UserIDs from Selected Items to do this query and delete them from database :
foreach (var userID in DataGridSelectedUserIDs)
{
var findQ = (from f in dbEntities.RelCUs
where f.UserID == userID && f.CourseID == currCourse.CourseID
select f);
foreach (var relCu in findQ)
{
dbEntities.RelCUs.Remove(relCu);
dbEntities.SaveChanges();
}
}
i have The CourseID, but i don't know how to get the UserIDs! my idea is to add a checkbox column and get checked items UserID but i don't know how. i searched but possible solution like these didn't worked for me: How to delete selected rows (using checkbox) in wpf datagrid
Get data of specific cell from selected row in DataGrid WPF C#
cause i don't want to add another field like "IsSelected" to table.
thanks alot:)