2013-03-22 83 views
0

我想從TableRow獲取所有數據,當點擊WPF時點擊行。如何從WPF中FlowDocument的TableRow TableRow獲取TableCell值?

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); 
    } 
} 

請幫助...

+0

對不起,這是.NET 4.5的版本,我使用的4.0 :(任何其他的解決方案在這裏禁用 – Kernel 2013-03-22 18:37:33

+0

朋友,TableCell的項目性質如何啓用 – Kernel 2013-03-23 05:34:16

+0

的TableRow時間tr =發件人爲的TableRow; TableCellCollection TC = tr.Cells ; //我無法訪問tc.Item,因爲它顯示這樣的錯誤.. – Kernel 2013-03-23 06:26:36

回答

1

我知道這是有點晚了,你可能不會還在這裏,更何況還是在這個項目上,但對於那些誰可能在將來查看此:從每個單元獲取數據,之後

TableRow tr = sender as TableRow; 

做類似如下:

// 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())); 
} 

它migh閱讀FlowDocument層次結構是個好主意。一個體面的地方開始是MSDN's Documentation。 。