private static object ResetNewItemTemplate(object obj) { DataGridControl datagrid = obj as DataGridControl; if (null == datagrid) { return(null); } // Get the row for CollectionView.NewItemPlaceholder DataGridRow row = datagrid.GetRow(CollectionView.NewItemPlaceholder); if (null == row) { return(null); } // Ensure it's template is correct ControlTemplate template = GetTemplate(datagrid); if (null == template) { template = GetDefaultTemplate(datagrid); } if (row.Template != template) { row.Template = template; row.UpdateLayout(); } return(null); }
/// <summary> /// Gets the <c>DataGridRow</c> for the specified item. /// </summary> /// <param name="dataGrid">The <c>DataGrid</c>.</param> /// <param name="item">The item.</param> /// <returns>The <c>DataGridRow</c> for the specified item.</returns> public static DataGridRow GetRow(this DataGridControl dataGrid, object item) { if (dataGrid == null) { throw new ArgumentNullException("dataGrid"); } int index = dataGrid.Items.IndexOf(item); // 3/23/2010 - Ensure index is valid (http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=4710#17370) return((index != -1) ? dataGrid.GetRow(index) : null); }
/// <summary> /// 获取DataGrid控件单元格 /// </summary> /// <param name="dataGrid">DataGrid控件</param> /// <param name="rowIndex">单元格所在的行号</param> /// <param name="columnIndex">单元格所在的列号</param> /// <returns>指定的单元格</returns> public static DataGridCell GetCell(this DataGrid dataGrid, int rowIndex, int columnIndex) { DataGridRow rowContainer = dataGrid.GetRow(rowIndex); if (rowContainer != null) { DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer); DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); if (cell == null) { dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[columnIndex]); cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); } return(cell); } return(null); }