[英]How to Get data of specific cell from DataGrid that fill by multiple tables
i have a DataGrid that fill by multiple tables by Entity-FrameWork by this Code: 我有一个DataGrid,由本代码通过Entity-FrameWork填充多个表:
var Qselect = (from w in db.Workshops
join wt in db.WorkshopTypes on w.WorkshopTypeId equals wt.WorkshopTypeId
join tt in db.TransferTypes on w.WorkshopTransfer equals tt.TransferTypeId
where w.WorkshopDate.Contains("1395/05/01")
orderby w.WorkshopDate
select new
{
WorkshopId = w.WorkshopId,
WorkshopDate = w.WorkshopDate,
WorkshopTypeId = wt.WorkshopTypeName,
WorkshopDetails = w.WorkshopDetails,
FusionId = w.FusionId,
WorkshopTransfer = tt.TransferTypeName,
WorkshopWeight = w.WorkshopWeight
}).Take(10);
grdWorkshop.ItemsSource = Qselect.ToList();
and i Create my DataGrid By this Code 我通过此代码创建我的DataGrid
<DataGrid x:Name="grdWorkshop" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="id" Width="50" Binding="{Binding WorkshopId}" />
<DataGridTextColumn Header="Date" Width="140" Binding="{Binding WorkshopDate }"/>
<DataGridTextColumn Header="Type" Width="110" Binding="{Binding WorkshopTypeId }"/>
<DataGridTextColumn Header="Detail" Width="220" Binding="{Binding WorkshopDetails }"/>
<DataGridTextColumn Header="Series" Width="80" Binding="{Binding FusionId }"/>
<DataGridTextColumn Header="Transfer" Width="130" Binding="{Binding WorkshopTransfer }"/>
<DataGridTextColumn Header="Weight" Width="100" Binding="{Binding WorkshopWeight }"/>
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu >
<MenuItem Header="Add" Click="AddWorkshopItem" />
<MenuItem Header="Edit" Click="EditWorkshopItem" />
<MenuItem Header="Delete" Click="DeleteWorkshopItem" />
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
Now i want to Edit Or Delete My Rows by Context Menu And Then Do this by Stored procedures. 现在我想通过上下文菜单编辑或删除我的行然后通过存储过程执行此操作。 Now I Want to Get The id of selected row in Data Grid To Delete or edit Rows.
现在我想获取数据网格中选定行的ID以删除或编辑行。 How I Can Get This??
我怎么能得到这个? I am using Entity-FrameWork And Full Row SelectionUnit.
我正在使用Entity-FrameWork和Full Row SelectionUnit。
i see this code and was work. 我看到这个代码并且工作正常。 but in my project does not work.
但在我的项目中不起作用。 i think it because of i join more than 1 table.
我认为这是因为我加入了超过1张桌子。
int id = (grdWorkshop.SelectedItem as Workshop).WorkshopId;
Thanks. 谢谢。
Finally i get my answer 最后我得到了答案
class CWorkshop
{
public decimal? WorkshopWeight { get; set; }
public int WorkshopId { get; set; }
public string WorkshopDate { get; set; }
public string WorkshopTypeId { get; set; }
public string WorkshopDetails { get; set; }
public int? FusionId { get; set; }
public string WorkshopTransfer { get; set; }
}
i changed my query by this class like this. 我这样改变了我的查询。 of course with full privet variables and properties.
当然还有完整的女贞变量和属性。
var Qselect = (from w in db.Workshops
join wt in db.WorkshopTypes on w.WorkshopTypeId equals wt.WorkshopTypeId
join tt in db.TransferTypes on w.WorkshopTransfer equals tt.TransferTypeId
where w.WorkshopDate.Contains("1395/05/01")
orderby w.WorkshopDate
select new CWorkshop()
{
WorkshopId = w.WorkshopId,
WorkshopDate = w.WorkshopDate,
WorkshopTypeId = wt.WorkshopTypeName,
WorkshopDetails = w.WorkshopDetails,
FusionId = w.FusionId,
WorkshopTransfer = tt.TransferTypeName,
WorkshopWeight = w.WorkshopWeight
}).Take(10);
then get my data by this code. 然后通过此代码获取我的数据。 it was so easy
真是太容易了
int id = (grdWorkshop.SelectedItem as CWorkshop).WorkshopId;
i hope it was useful. 我希望它有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.