DataGrid 得到DataGridRow 和DataGridColumn
/* ----------------------------------------------------------
文件名称: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 = ; 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;
}
}
}
DataGrid 得到DataGridRow 和DataGridColumn的更多相关文章
- WPF DataGrid显格式
Guide to WPF DataGrid formatting using bindings Peter Huber SG, 25 Nov 2013 CPOL 4.83 (13 votes) ...
- WPF DataGrid Custommization using Style and Template
WPF DataGrid Custommization using Style and Template 代码下载:http://download.csdn.net/detail/wujicai/81 ...
- WPF 4 DataGrid 控件(自定义样式篇)
原文:WPF 4 DataGrid 控件(自定义样式篇) 在<WPF 4 DataGrid 控件(基本功能篇)>中我们已经学习了DataGrid 的基本功能及使用方法.本篇将继续 ...
- datagridcolumn单元格怎么显示查询到的某个表的字段值(字段值可能为多个)
例如,在之前做的项目中,查询mhz_xckcr表,select出某个业务的现场勘察人信息,select出的现场勘察人姓名(可能有多个)要在前台datagrid的一个datagridcolmn单元格显示 ...
- WPF之DataGrid的LoadingRow事件
利用DataGrid的LoadingRow事件,可以进行设置DataGrid的DataGridRow的属性(例如样式:背景色.前景色:是否可修改数据) 实例代码如下: private void Dat ...
- datagrid和combobox简单应用
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- DataGrid 滚动特定的行或者列
DataGrid 滚动特定的行或者列. DataGrid.ScrollIntoView Method (Object, DataGridColumn) .NET Framework 4.5 Silve ...
- DataGrid 獲取 制定 row Col 單元格
public static class DataGridHelper { /// <summary> /// Gets the v ...
- jQuery DataTables 使用手册(精简版)
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/5182940.html 前排提醒,这个插件能不用就不用,那么多好的插件等着你,为什么要用它呢?就算用easyui的 ...
随机推荐
- 深入剖析java迭代器以及C#迭代器!
目录: 知道迭代器接口Iterable 为什么java的for增强可以自动迭代 那些类可以被迭代 通过什么方法迭代 1.知道迭代器接口Iterable 解析: 迭代器(iterator)是一种对象,它 ...
- IS-IS完整笔记
IS-IS笔记大全 1.公开,ISO国际标准化组织(按照中文顺序翻译) 中间系统到中间系统 双栈.集成 数据传递机制 Cons面向连接网络服务(TCP) Clns缺少链接网络服务(UDP) Is-is ...
- RDS最佳实践(一)—如何选择你的RDS
在去年双11之前,为了帮助商家准备天猫双11的大促,让用户更好的使用RDS,把RDS的性能发挥到最佳,保障双11当天面对爆发性增加的压力,不会由于RDS的瓶颈导致系统出现问题,编写了 RDS的最佳实践 ...
- 如何让eclipse在程序修改后,点击运行可以自动保存。
preferences>run/debug>launching里面save required dirty editors before launching选always就自动保存咯选pro ...
- 201521123088《java程序设计》第三周学习总结
1. 本周学习总结 本周学习了关于Java的封装,所谓封装就是将属性私有化,提供公有的方法访问私有属性 2. 书面作业 代码阅读 public class Test1 { private int i ...
- JAVA课设---五子棋
1.团队博客链接 JAVA课设-五子棋-团队博客 2.个人负责模块: ①对鼠标事件的处理 , 此模块需处理五子棋的放置问题.颜色转换问题.以及当五子连线时弹出窗口显示结果. ②对MainFrame中主 ...
- 201521123003《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...
- eclipse 项目引入第三方jar包 3种方法
我们在用Eclipse开发程序的时候,经常要用到第三方jar包.引入jar包不是一个小问题,由于jar包位置不清楚,而浪费时间.下面配图说明3种Eclipse引入jar包的方式. 1.最常用的普通操作 ...
- PHPStorm调试PHP代码~实际操作+mark~~
因为wamp自己已经下载了xdebug,只要配置开启就行了. 1. 配置php.ini(有就打开注释,没有就加上) XDEBUG Extension[xdebug]zend_extension =&q ...
- Java-byte[]与16进制字符串互转
转自: http://www.cnblogs.com/freeliver54/archive/2012/07/30/2615149.html Java中byte用二进制表示占用8位,而我们知道16进制 ...