Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand you, yo have something like "master/detail", AKA you click on a datagrid row and you want a couple of textboxes filled.</p> <p>So, when you click on a row, launch the SelectionChanged event, get the element attached to that row (the Employee) and assign it to a "SelectedEmployee" property. The textboxes' datacontext is that SelectedEmployee. Bind every textbox to a SelectedEmployee property (empid, empname...)</p> <p>Is that what you want? :)</p> <p>Here is the example:</p> <pre><code>&lt;StackPanel&gt; &lt;sdk:DataGrid x:Name="datagrid" SelectionChanged="DataGrid_SelectionChanged"&gt; &lt;/sdk:DataGrid&gt; &lt;TextBox Text="{Binding SelectedEmployee.Id}" /&gt; &lt;TextBox Text="{Binding SelectedEmployee.EmpName}" /&gt; &lt;/StackPanel&gt; </code></pre> <p>I have a DataGrid (the name is because Im using codebehind in this example). A Datagrid with data and two textboxes that will contain the data of the selected row on the datagrid.</p> <pre><code> private ObservableCollection&lt;Employee&gt; employees; public MainPage() { InitializeComponent(); employees = new ObservableCollection&lt;Employee&gt;(); employees.Add(new Employee {Id = 1, EmpName = "Raj"}); employees.Add(new Employee {Id = 2, EmpName = "Jesus"}); datagrid.ItemsSource = Employees; Page.DataContext = this; } private Employee _selectedEmployee; public ObservableCollection&lt;Employee&gt; Employees { get { return employees; } } public Employee SelectedEmployee { get { return _selectedEmployee; } set { _selectedEmployee = value; RaisePropertyChanged("SelectedEmployee"); } } private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { SelectedEmployee = datagrid.SelectedItem as Employee; } </code></pre> <p>Again the codebehind shit, but the idea is that. You have a ItemsSource binded to your DataGrid and you have a SelectedEmployee property.</p> <p>So, when I click on a row, the SelectedChanged event will be launched and you have to get the Employee asigned to that row, putting it to the SelectedEmployee property and because the textboxes are assigned to that property, you will see them filled.</p> <p>Better now? :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload