DataGrid 獲取 制定 row Col 單元格
public static class DataGridHelper
{
/// <summary>
/// Gets the visual child of an element
/// </summary>
/// <typeparam name="T">Expected type</typeparam>
/// <param name="parent">The parent of the expected element</param>
/// <returns>A visual child</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;
}
/// <summary>
/// Gets the specified cell of the DataGrid
/// </summary>
/// <param name="grid">The DataGrid instance</param>
/// <param name="row">The row of the cell</param>
/// <param name="column">The column index of the cell</param>
/// <returns>A cell of the DataGrid</returns>
public static DataGridCell GetCell(this DataGrid grid, DataGridRow row, int column)
{
if (row != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
if (presenter == null)
{
grid.ScrollIntoView(row, grid.Columns[column]);
presenter = GetVisualChild<DataGridCellsPresenter>(row);
}
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
return cell;
}
return null;
}
/// <summary>
/// Gets the specified cell of the DataGrid
/// </summary>
/// <param name="grid">The DataGrid instance</param>
/// <param name="row">The row index of the cell</param>
/// <param name="column">The column index of the cell</param>
/// <returns>A cell of the DataGrid</returns>
public static DataGridCell GetCell(this DataGrid grid, int row, int column)
{
DataGridRow rowContainer = grid.GetRow(row);
return grid.GetCell(rowContainer, column);
}
/// <summary>
/// Gets the specified row of the DataGrid
/// </summary>
/// <param name="grid">The DataGrid instance</param>
/// <param name="index">The index of the row</param>
/// <returns>A row of the DataGrid</returns>
public static DataGridRow GetRow(this DataGrid grid, int index)
{
DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
if (row == null)
{
// May be virtualized, bring into view and try again.
grid.UpdateLayout();
grid.ScrollIntoView(grid.Items[index]);
row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
}
return row;
}
/// <summary>
/// Gets the selected row of the DataGrid
/// </summary>
/// <param name="grid">The DataGrid instance</param>
/// <returns></returns>
public static DataGridRow GetSelectedRow(this DataGrid grid)
{
return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);
}
}
DataGrid 獲取 制定 row Col 單元格的更多相关文章
- C# DataGridView的單元格中只能輸入數字
控件類型:DataGridView 控件名稱:dgvGift_Condition 裏面用到的:IsNumeric.NotePastText.RestoreText 等請參見 前一日志“TextBox中 ...
- jquery html 獲取或設置
jquery提供操作html元素的屬性和內容的強大方法. DOM就是獨立于平台和語言的界面,允許程序和腳本動態訪問和改變DOM的內容,結構和樣式. 獲取內容:text(),html(),val(),a ...
- 實際案例: 獲取臨時票証 (JsApi Ticket)
專案中選用大名鼎鼎的 Senparc 微信開發套件 獲取臨時票證處理常式的程式碼 (GetgVXinInfo.ashx) using Senparc.Weixin; using Senparc.Wei ...
- 實際案例: 已知要獲取臨時票証 (JsApi Ticket) 才能調用的接口
需獲取票証才能調用的接口,簡單列示如下: 一.基礎類 1. wx.checkJsApi (當前客戶端是否支持指定JS) 二.分享類 1.wx.onMenuShareTimeline (分享到朋友圈)2 ...
- ASP.NET MVC 單元測試系列
ASP.NET MVC 單元測試系列 (7):Visual Studio Unit Test 透過 Visual Studio 裡的整合開發環境 (IDE) 結合單元測試開發是再便利不過的了,在 Vi ...
- C#-Windows服務以LocalSystem賬戶安裝的話無法獲取我的文檔路徑
如圖,如果Window服務以上圖 Account安裝運行,則無法獲取到 以下路徑: System.Environment.GetFolderPath(Environment.SpecialFolder ...
- [转] [Visual Studio 2012] 找回 建立單元測試 選單
原文链接:http://www.dotblogs.com.tw/yc421206/archive/2013/03/08/95920.aspx Step1.建立選單 在VS2012選單,Tools→Cu ...
- DataGrid中取HyperLinkColumn列的值,处理DataGrid中绑定的特殊字符
DataGrid中取HyperLinkColumn列的值. /// <summary> /// 对datagrid中标签进行编码,处理特殊字符 /// </summary> / ...
- easyui datagrid 相关取数据总结
easyui 中datagrid$('#dg').datagrid('getSelected');返回第一个被选中的行或如果没有选中的行则返回null.$('#dg').datagrid('getSe ...
随机推荐
- python面试的100题(2)
def print_directory_contents(sPath): """ 这个函数接收文件夹的名称作为输入参数 返回该文件夹中文件的路径 以及其包含文件夹中文件的 ...
- 关于layui的日期和时间组件laydate闪屏的坑
https://blog.csdn.net/liangwenli_/article/details/82786713 jsp页面: <input type="text" cl ...
- spring(三):BeanDefiniton
- 2.7.5 元素定位(主推xpath、cssSelector) ❀❀❀
定位方式选择: 1. 当页面元素有id属性时,最好尽量用id来定位.但由于现实项目中很多程序员其实写的代码并不规范,会缺少很多标准属性,这时就只有选择其他定位方法. 2. xpath很强悍,但定位性能 ...
- 项目中的process.bpmn的读-过程
1.这次项目中遇到了process.bpmn类的封装好的类.怎么读呢?不知道,一周过去了,总算明白点. 2.首先也是从Controller开始,走进service层,比如mybatis,调用的就不是m ...
- 安装 Navicat for MySQL
安装 Navicat for MySQL 下载地址:https://www.pcsoft.com.cn/soft/20832.html
- C++实现索引堆及完整测试代码
首先贴一篇我看的博客,写的很清楚.作者:Emma_U 一些解释 索引堆首先是堆,但比堆肯定是更有用. 用处: 1.加速. 索引堆存储的是索引,并不直接存储值.在堆上浮下沉的元素交换的时候,交换索引可比 ...
- sqlserver 查看视图语句
本人sql小白一个,在项目中遇到了视图的使用,但是不知道视图的语句怎么查看,所以在网上搜索了一下,查到了一下的查看方式,再次记录一下: 方法一->前提: 已经创建好的视图 sp_helptext ...
- MS Sqlserver删除字段最后的多余字符
存在这样一些数据 ,,,,dga bc,,aaaa,,,,,,,,dga bc,,aaaa,,,,,,,dga bc,,aaaa,,,,,,,dga bc,,aaaa,,,,,, 需要将最后多余的逗号 ...
- cannot be resolved to a type解决方法!!!
小楼今天在做一个Java项目的时候遇到一个大家经常遇到的问题:XXX cannot be resolved to a type 看到一百多个errors时的时候,小楼也是被吓得赶紧去找度娘. 归纳一下 ...