我正在尝试从我的数据网格中的单元格中获取值,下面的代码将单元格中的值作为“System.Windows.Controls.Textblock”返回,而我想从单元格中获取实际值。我正在尝试使用的列是代码中的ID。
任何帮助将不胜感激,谢谢!
<sdk:DataGrid AutoGenerateColumns="False" Height="245" HorizontalAlignment="Left" Margin="12,77,0,0" Name="dataIssue" VerticalAlignment="Top" Width="512">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=ID}" Header="ID"/>
<sdk:DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=subject}" Header="Subject"/>
<sdk:DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=project_ID}" Header="Project ID"/>
<sdk:DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=elapsed}" Header="Time"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
public void StartTimer(object o, RoutedEventArgs sender)
{
if ((string)timeButton.Content == "Start")
{
string getID = dataIssue.Columns[0].GetCellContent(dataIssue.SelectedItem).ToString();
child.GetID = getID;
watch.Start();
timeButton.Content = "Stop";
}
}
答案 0 :(得分:1)
尝试这样......
TextBlock txtBlock=(TextBlock) myGrid.Columns[1].GetCellContent(myGrid.SelectedItem);
string retrivingtext = txtBlock.Text;
此处myGrid=GridName:
TextBlock =列类型