0
A
回答
0
// Getting Data from Grid Cell
string cellContent = ((TextBox)(GetCell(3).Content)).Text; //As I want the value of 3 column
public DataGridCell GetCell(int column)
{
DataGridRow rowContainer = GetRow();
if (rowContainer != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
// Try to get the cell but it may possibly be virtualized.
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
if (cell == null)
{
// Now try to bring into view and retreive the cell.
customDataGrid.UCdataGridView.ScrollIntoView(rowContainer, customDataGrid.UCdataGridView.Columns[column]);
cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
}
return cell;
}
return null;
}
public DataGridRow GetRow()
{
DataGridRow row = (DataGridRow)customDataGrid.UCdataGridView.ItemContainerGenerator.ContainerFromIndex(_currentRowIndex);
if (row == null)
{
// May be virtualized, bring into view and try again.
customDataGrid.UCdataGridView.UpdateLayout();
customDataGrid.UCdataGridView.ScrollIntoView(customDataGrid.UCdataGridView.Items[_currentRowIndex]);
row = (DataGridRow)customDataGrid.UCdataGridView.ItemContainerGenerator.ContainerFromIndex(_currentRowIndex);
}
return row;
}
public static T GetVisualChild<T>(Visual parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
// Setting Data to Grid Cell
if (GetCell(3).Content is TextBlock) // if grid cell is not editable
{
((TextBlock)(GetCell(3).Content)).Text = "sometext";
}
else // TextBox - if grid cell is editable
{
((TextBox)(GetCell(3).Content)).Text = "sometext";
}
2
這並不容易,因爲它應該是在WPF設置在WPF數據網格中的單元格的值,它是所有關於選擇視覺兒童(WPF'視覺'對象類型)。 This blog post很好地解釋瞭如何完成它。谷歌它,你可能會發現更多。
相關問題
- 1. 如何使用列和行索引值設置datagrid單元格的值?
- 2. Datagrid中,獲取和設置單獨的單元格值
- 3. 如何獲取Datagrid行索引以獲取上一行的單元格值
- 4. 獲得具有給定行索引和列索引的datagrid單元格的值
- 5. 如何通過單擊來返回表格單元格的行和列索引
- 6. WPF Toolkit DataGrid SelectionChanged獲取單元格值
- 7. 如何獲取DataGrid中剛剛編輯的單元格的行和單元格的索引
- 8. 如何從WPF 4.0 Datagrid中的特定單元格獲取值?
- 9. 如何通過在DataTable中提供列名來獲取行值
- 10. 如何按C#中Datatable的單元格值獲取行索引
- 11. WPF Datagrid。獲取選定行的每個單元格的值
- 12. 如何獲取和設置單元格的值包含圖像?
- 13. 如何獲取WPF網格中選定單元格的行索引
- 14. 如何從WPF DataGrid中讀取單元格中的值?
- 15. WPF Datagrid讀取單元格值
- 16. 如何通過行和列的索引更改表格單元格的顏色?
- 17. 如何獲取WPF DataGrid SelectedCellsChanged中的單元格模板datacontext?
- 18. 獲取來自81元素索引數組的行和列值
- 19. 從WPF Datagrid獲取單元格值(在vb中)
- 20. 獲取DataGrid行索引的值?
- 21. 如何從Extjs的網格單元中獲取父行索引?
- 22. wpf datagrid行中的小計單元格
- 23. 如何通過單擊按鈕來獲取tableview單元格中textfield的值?
- 24. c#datagrid單元格提取
- 25. 獲取其他單元格的值DataGrid WPF
- 26. WPF DataGrid:如何獲取單元格的綁定表達式?
- 27. 如何爲WPF DataGrid獲取單元格級別的ComboBox?
- 28. 如何讀取單元格值隱藏colomn在WPF Datagrid的
- 29. Java HashMap:如何通過索引獲取密鑰和值?
- 30. WPF工具包DataGrid SelectionChanged設置單元格值
http://stackoverflow.com/questions/1295843/wpf-datagrid-how-do-you-get-the-content-of-a-single-cell看它是否有助於阿布舍克 – Devjosh