I'm unable to get value from selected cell
DataGrid
<DataGrid x:Name="dataGrid" Margin="0,15,0,-0.333" GridLinesVisibility="None" HeadersVisibility="None" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" Width="225" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" Background="#FF6E6E6E" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ColumnWidth="225" BorderBrush="{x:Null}" CellStyle="{StaticResource NameCellStyle}" AutoGenerateColumns="False" BorderThickness="0" SelectionChanged="dataGrid_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn x:Name="location" Binding="{x:Null}" ClipboardContentBinding="{x:Null}" CanUserResize="False" Width="0" MinWidth="0"/>
<DataGridTextColumn x:Name="title" Binding="{x:Null}" ClipboardContentBinding="{x:Null}" IsReadOnly="True" Width="225" CellStyle="{StaticResource MyDataGridCell}" FontSize="18"/>
</DataGrid.Columns>
</DataGrid>
I've tried following to get string from selected row
int i = dataGrid.SelectedIndex;
DataRowView v = (DataRowView)dataGrid.Items[i];
string s = (string)v[0];
MessageBox.Show(s);
Error
"An unhandled exception of type 'System.InvalidCastException' occurred in MissionControl M.exe"
"Additional information: Unable to cast object of type 'Item' to type 'System.Data.DataRowView'."
Some of the questions/solutions that doesn't work for me
WPF Datagrid Get Selected Cell Value https://social.msdn.microsoft.com/Forums/vstudio/en-US/d8434785-82b8-4e7a-8723-466de6b35845/how-to-get-cell-value-to-a-string-for-wpf-datagrid?forum=wpf
edit: I just moved to WPF from WinForms and I use the DataGrid as a menu. I'm trying to move my winfor project functionality to this WPF project.