Reputation: 165
I want to get all the data from a TableRow
, when row is clicked in WPF
.
currentRow = tab.RowGroups[0].Rows[r];
currentRow.MouseLeftButtonDown += new MouseButtonEventHandler(test);
void test(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
try
{
TableRow tr = sender as TableRow;
// After that what i do to read TableCell Value
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Please help...
Upvotes: 2
Views: 2063
Reputation: 581
I know it's a little late, and you're probably not still here, let alone still on this project, but for those who might view this in the future: To get the data from each cell, after
TableRow tr = sender as TableRow;
do something like the following:
// I imagine you'd want to start a list here
// that will hold the contents of your loops' results.
List<string> resultsList = new List<string>();
foreach(var tableCell in tr.Cells)
{
// May want to start another list here in case there are multiple blocks.
List<string> blockContent = new List<string>();
foreach(var block in tableCell.Blocks)
{
// Probably want to start another list here to which to add in the next loop.
List<string> inlineContent = new List<string>();
foreach(var inline in block.Inlines)
{
// Implement whatever in here depending the type of inline,
// such as Span, Run, InlineUIContainer, etc.
// I just assumed it was text.
inlineContent.Add(new TextRange(inline.ContentStart, inline.ContentEnd).Text);
}
blockContent.Add(string.Join("", inlineContent.ToArray()));
}
resultsList.Add(string.Join("\n", blockContent.ToArray()));
}
It might be a good idea to read up on the FlowDocument hierarchy. A decent place to start is MSDN's Documentation.
Upvotes: 2