Элементы Datagrid в WPF
<DataGrid x:Name="GrdSubject" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MaxWidth="600" Background="{x:Null}" Margin="10,130,10,10" SelectionChanged="GrdSubject_SelectionChanged"> <DataGrid.BorderBrush> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="#FFFFF2F2" Offset="1"/> </LinearGradientBrush> </DataGrid.BorderBrush> <DataGrid.Columns> <DataGridTextColumn x:Name="ClId" Header="ID" Width="100" Visibility="Visible" Binding="{Binding SubId}"/> <DataGridTextColumn x:Name="ClSubject" Header="Subject" Width="250" Binding="{Binding SubName}"/> <DataGridTextColumn x:Name="ClStatus" Header="Status" Width="100" Binding="{Binding SubStatus}"/> </DataGrid.Columns> </DataGrid>
public class Subject { public int SubId { set; get; } public string SubName { set; get; } public string SubStatus { set; get; } }
Что я уже пробовал:
string id = ""; string sub="; var sub = new Subject(); if (GrdSubject.SelectedItem!=null) { sub = GrdSubject.SelectedItem as Subject; if (sub!=null) { id = sub.SubId.ToString(); MessageBox.Show(id.Length.ToString()); //just to check the word results always 200 but in real is 2 or 3 MessageBox.Show(sub.SubName.Length.ToString()); //just to check the word results always 200 but in real is 5 or 6 and this is the problem "id " many spaces after the word to reach 200 as length } }