c# - Get selected row item in DataGrid WPF doesn't work -
To get selected line items, I have been read that this should be done:
& lt; DataGrid ItemsSource = "{Bound Path = Customer}" SelectedItem = "{Binding Path = Selected Customers, Mode = Two}" / & gt; Customer customer = (customer) myDataGrid.SelectedItem; First in xaml - I put it, this error is nothing or I do not know how to use it. How can I get the selected row in the C # code? This error visual studio client does not exist in the C # Row code
I'll thank you for help :) Thanks.
It's hard to know what exactly you wanted:) But here's an example of how to pull information from the datagrid, it did not include a lot of those dams, so this information is pure.
Xaml & lt; Grid & gt; & Lt; Grid.RowDefinitions & gt; & Lt; Roadfinion height = "*" /> & Lt; Roadfinion height = "*" /> & Lt; /Grid.RowDefinitions> & Lt; Data Grid Grid Rau = "0" name = "dg" /> & lt; Button grid Rows = "1" name = "btn" click = "btn_click" /> & Lt; / Grid & gt; Codebehind list & lt; SomeInfo & gt; List = new list & lt; SomeInfo & gt; (); Public Manvindo () {Initialization (); List.Add (New SomeInfo () {name = "pc", description = "computer", id = 1}); List.Add (New SomeInfo () {name = "ps", description = "playstation", id = 2}); List.Add (New SomeInfo () {name = "XB", Description = "Xbox", id = 3}); This.dg.ItemsSource = list; } Public class SomeInfo {public string name {get; Set; } Public string description {get; Set; } Receive the public int id { Set; }} Private Zero btn_Click (Object Sender, RoutedEventArgs e) {if (dg.SelectedIndex! = -1) Sender as DataGrid dataGrid = DataGrid; DataGridRow dg.ItemContainerGenerator.ContainerFromIndex (dg.SelectedIndex); Data Gridcel RowColumn = dg.Column [0] .GetCellContent (Row). Basic as DataGridCell; Btn.Content = ((TextBlock) RowColumn.Content BTN_click collects all the information, where the final 2 test creates my data grid. Hope this will help you: )
------------------ Edit ------------------- ------- The comment below gives you only
private zeros btn_Click (object Analyst, RoutedEventArgs e) {if (dg.SelectedIndex! = -1) from as {DataGrid dataGrid = Detagrid; DataGridRow = (DataGridRO) DG Edit Container Generator. ContainerFrand Index (DG Select Index); Data Gridcel RowColumn = dg.Column [0] .GetCellContent (line). Originally as DataGridCell; Btn.Content = ((TextBlock) RowColumn.Content). Text; }} Dg = Your Data Grid DG Change the column [0] = 0, which you want information from BTN. Content = Do you want content --- ----------- 2 Edit ------------ You need to get the index of the selected row int index = dg. selectedIndex; BTN.Source = Index; Or if you do not want to store an intro
btn.content = dg.SelectedIndex;
Comments
Post a Comment