C
C#16mo ago
ApathyErr

✅ How to get data from the first cell of a selected row?

6 Replies
SinFluxx
SinFluxx16mo ago
What/when do you mean? Presumably you're binding your DataGrid to something?
ApathyErr
ApathyErrOP16mo ago
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ID}" ClipboardContentBinding="{x:Null}" Header="ID" Width="40"/>
<DataGridTextColumn Binding="{Binding Name}" ClipboardContentBinding="{x:Null}" Header="Name"/>
<DataGridTextColumn Binding="{Binding email}" ClipboardContentBinding="{x:Null}" Header="e-mail"/>
<DataGridTextColumn Binding="{Binding Telephone}" ClipboardContentBinding="{x:Null}" Header="telephone number"/>
<DataGridTextColumn Binding="{Binding Region}" ClipboardContentBinding="{x:Null}" Header="Region"/>
<DataGridCheckBoxColumn Binding="{Binding Subscribed}" ClipboardContentBinding="{x:Null}" Header="Subscribe" Width="30"/>
<DataGridTextColumn Binding="{Binding Comment}" ClipboardContentBinding="{x:Null}" Header="Comment"/>
</DataGrid.Columns>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ID}" ClipboardContentBinding="{x:Null}" Header="ID" Width="40"/>
<DataGridTextColumn Binding="{Binding Name}" ClipboardContentBinding="{x:Null}" Header="Name"/>
<DataGridTextColumn Binding="{Binding email}" ClipboardContentBinding="{x:Null}" Header="e-mail"/>
<DataGridTextColumn Binding="{Binding Telephone}" ClipboardContentBinding="{x:Null}" Header="telephone number"/>
<DataGridTextColumn Binding="{Binding Region}" ClipboardContentBinding="{x:Null}" Header="Region"/>
<DataGridCheckBoxColumn Binding="{Binding Subscribed}" ClipboardContentBinding="{x:Null}" Header="Subscribe" Width="30"/>
<DataGridTextColumn Binding="{Binding Comment}" ClipboardContentBinding="{x:Null}" Header="Comment"/>
</DataGrid.Columns>
I want to put the id from the selected string into a variable, but I don't know how to do it
SinFluxx
SinFluxx16mo ago
DataGrid has a SelectedItem property, and you can create a Binding for that so you can access whatever's selected
ApathyErr
ApathyErrOP16mo ago
Can you give an example?
SinFluxx
SinFluxx16mo ago
<DataGrid ItemsSource="{Binding CollectionOfSomethings}" SelectedItem="{Binding SelectedSomething, Mode=TwoWay}" > Then you can access whatever row is currently selected through SelectedSomething, and get SelectedSomething.Id
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server