c# - How to get the row index of a WPF Datagrid? -
I am using image control column in wpf datagrid. That control is used to remove the row in the datagrid if click is done. Anyone can tell me how to select the entire line of the grid, click on control, my code below the event is now.
XML code:
& lt; DataGrid x: name = "dg" & gt; & Lt; DataGrid.Columns & gt; & Lt; DataGridTextColumn header = "id" binding = "{binding path = area id}" /> & Lt; DataGridTextColumn Header = "Sector" Binding = "{Binding Path = Sector ID" /> & Lt; DataGridTemplateColumn Width = "40" & gt; & Lt; DataGridTemplateColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; Image X: name = "imgDel" source = "delete.png" stretch = "none" MouseLeftButtonDown = "imgDel_MouseLeftButtonDown" /> & Lt; / DataTemplate & gt; & Lt; /DataGridTemplateColumn.CellTemplate> & Lt; / DataGridTemplateColumn & gt; & Lt; /DataGrid.Columns> & Lt; / Data grid & gt; Behind Code:
Private Zero imgDel_MouseLeftButtonDown (Object Sender, MouseButtonEventArgs e) {var INX = dg.SelectedIndex; } My requirement is when I click on the image control in the row, it should remove the entire data from the datacrint. My data has been compiled from the grid archive.
Thanks
If you have the DataGridRow object that inside your image you Finding VisualTreeHelper can be used to try to get a reference.
Private zero imgDel_MouseLeftButtonDown (Object Sender, MouseButtonEventArgs e) {DependencyObject dataGridRow = DependencyObject this as; Whereas (dataGridRow = Null & amp;! & DataGridRow (DataGridRow!)) DataGridRow = VisualTreeHelper.GetParent (dataGridRow); If (dataGridRow! = Null) {// Now there is a reference to the row in DataGridRow,}}
Comments
Post a Comment