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的 ...
随机推荐
- 如何在C++中产生随机数
C++中没有自带的random函数,要实现随机数的生成就需要使用rand()和srand().不过,由于rand()的内部实现是用线性同余法做的,所以生成的并不是真正的随机数,而是在一定范围内可看为随 ...
- 201521123079《java程序设计》第8周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4-1) 1.1 实验总结 这题主要是对函 ...
- 201521123016 《Java程序设计》第2周学习总结
1. 本周学习总结 JAVA中string对象创建后不可修改. 使用StringBuilder编写代码,减少内存空间的占用. 字符串使用"+"拼接,拼接后其他类型会被转化为字符串. ...
- 201521123056 《Java程序设计》第1周学习总结
1. 本周学习总结 java语言结构简单,但功能齐全,同时能够在不同系统平台上编译,但编译的前提是系统要有安装JVM(即java虚拟机),JVM是java实现跨平台的最核心部分.本周还学习了JDK.J ...
- 201521123093 java 第十四周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. MySQL中的库操作和表操作 库操作: 显示所有数据库: show databases; 创建数据库: crea ...
- 201521123109《java程序设计》第十周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 2. 书面作业 本次PTA作业题集异常.多线程 1. finally 题目4-2 1.1 截图你的提交结果( ...
- 201521123066 《Java程序设计》第十一周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用synch ...
- java:接口特性 接口与抽象类/普通类的区别
接口 书面定义: Java接口是一系列方法的声明,是一些方法特征的集合,一个接口只有方法的特征没有方法的实现,因此这些方法可以在不同的地方被不同的类实现,而这些实现可以具有不同的行为(功能). 在ja ...
- Sql Server——基础
前言: 在了解数据库之前,我们应该首先了解一下和数据库有关的知识,如:什么是数据,什么又是数据库等. 数据:描述事物的符号记录称为数据,它是数据库中存储的基本对象. 数据库(Datebase):数 ...
- Spring配置属性文件
在项目开发阶段和交付阶段数据库的连接信息往往是不同的,可以把这些信息写成属性文件,再在Spring中导入即可引用 jdbc.properties属性文件如下: jdbc.driverClassName ...