WPF:获取DataGrid控件单元格DataGridCell
- 转载:http://blog.csdn.net/jhqin/article/details/7645357
- /* ----------------------------------------------------------
- 文件名称:DataGridPlus.cs
- 作者:秦建辉
- MSN:splashcn@msn.com
- QQ:36748897
- 博客:http://blog.csdn.net/jhqin
- 开发环境:
- Visual Studio V2010
- .NET Framework 4 Client Profile
- 版本历史:
- V1.0 2012年06月07日
- WPF DataGrid控件扩展方法
- 参考资料:
- http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b7299e55-92e2-4a6b-8987-869fef8f22eb/
- ------------------------------------------------------------ */
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Media;
- namespace Splash.WPF
- {
- public static class DataGridPlus
- {
- /// <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;
- }
- /// <summary>
- /// 获取DataGrid的行
- /// </summary>
- /// <param name="dataGrid">DataGrid控件</param>
- /// <param name="rowIndex">DataGrid行号</param>
- /// <returns>指定的行号</returns>
- public static DataGridRow GetRow(this DataGrid dataGrid, int rowIndex)
- {
- DataGridRow rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
- if (rowContainer == null)
- {
- dataGrid.UpdateLayout();
- dataGrid.ScrollIntoView(dataGrid.Items[rowIndex]);
- rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
- }
- return rowContainer;
- }
- /// <summary>
- /// 获取父可视对象中第一个指定类型的子可视对象
- /// </summary>
- /// <typeparam name="T">可视对象类型</typeparam>
- /// <param name="parent">父可视对象</param>
- /// <returns>第一个指定类型的子可视对象</returns>
- 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;
- }
- }
- }
WPF:获取DataGrid控件单元格DataGridCell的更多相关文章
- WPF 获取DataGrid 控件选中的单元格信息
获取 DataGrid 选中的单元格的信息DataGridCellInfo cell_Info = this.studentTable.SelectedCells[0]; studentTableIt ...
- wpf 获取DataGrid某一个单元格,设置此单元格ToolTip内容和背景颜色
public void GetCell() { for (int i = 0; i < this.datagrid1.Items.Count; i++) ...
- WPF的DataGrid控件从excel里复制数据然后粘贴
WPF的DataGrid控件不能像winform的DataGridView控件一样,支持值的粘贴.WPF的DataGrid控件本质上是跟数据绑定联系在一起,所以需要进行复制粘贴的操作,可以在wpf里用 ...
- WPF 4 DataGrid 控件(自定义样式篇)
原文:WPF 4 DataGrid 控件(自定义样式篇) 在<WPF 4 DataGrid 控件(基本功能篇)>中我们已经学习了DataGrid 的基本功能及使用方法.本篇将继续 ...
- WPF 4 DataGrid 控件(进阶篇一)
原文:WPF 4 DataGrid 控件(进阶篇一) 上一篇<WPF 4 DataGrid 控件(自定义样式篇)>中,我们掌握了DataGrid 列表头.行表头.行.单元格相关的 ...
- WPF 4 DataGrid 控件(基本功能篇)
原文:WPF 4 DataGrid 控件(基本功能篇) 提到DataGrid 不管是网页还是应用程序开发都会频繁使用.通过它我们可以灵活的在行与列间显示各种数据.本篇将详细介绍WPF 4 中 ...
- WPF 4 DataGrid 控件(进阶篇二)
原文:WPF 4 DataGrid 控件(进阶篇二) 上一篇<WPF 4 DataGrid 控件(进阶篇一)>中我们通过DataGridTemplateColumn 类自定义编辑 ...
- WPF获取某控件的位置,也就是偏移量
原文:WPF获取某控件的位置,也就是偏移量 此段示例在MSDN中可见.XAML代码如下: <Window xmlns="http://schemas.microsoft.com/win ...
- WPF 自定义DataGrid控件样式
内容转自https://www.cnblogs.com/xiaogangqq123/archive/2012/05/07/2487166.html 一.DataGrid基本样式(一) 小刚已经把Dat ...
随机推荐
- mpls vpn剩余笔记
将IP地址映射为简单的具有固定长度的标签 用于快速数据包交换 20 3 1 8 在整个转发过程中,交换节点仅根据标记进行转发 标签交换路径(LSP) 多协议标签交换MPLS最初是为了提高转发速度而提出 ...
- MPLS LDP随堂笔记2
前一天排错 Acl 1 匹配所有ospf的数据包 (目的 ospf建立邻居关系 传递路由条目) 2 放行UDP报文 让LDP邻居能互相收发HELLO包 4 放行TCP报文 让LDP邻居能够建立TCP会 ...
- 转: 【Java并发编程】之二十一:并发新特性—阻塞队列和阻塞栈(含代码)
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17511147 阻塞队列 阻塞队列是Java5并发新特性中的内容,阻塞队列的接口是Java. ...
- 201521123079《java程序设计》第6周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖 ...
- 201521123095 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1. ...
- Markdown 模板
一个例子: 例子开始 1. 本章学习总结 今天主要学习了三个知识点 封装 继承 多态 2. 书面作业 Q1. java HelloWorld命令中,HelloWorld这个参数是什么含义? 今天学了一 ...
- Ajax【介绍、入门、解决Ajax中文、跨域、缓存】
什么是Ajax Ajax(Asynchronous JavaScript and XML) 异步JavaScript和XML Ajax实际上是下面这几种技术的融合: (1)XHTML和CSS的基于标准 ...
- Javascript跳转页面和打开新窗口等方法
1.在原来的窗体中直接跳转用onClick="window.location.href='你所要跳转的页面';" 2.在新窗体中打开页面用:onclick="window ...
- python新增nonlocal关键字
def fa(a): b = 2 def fb(): nonlocal b print(b) return fbc = 2fa(22)()# python作用域:LEGB
- java 使用redis 数据库
[TOC] java 使用redis 数据库 连接redis package com.wsc.redis.Test1; import java.util.List; import java.util. ...