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 ...
随机推荐
- Linux, Nginx - Deepin linux手动安装nginx和出现的问题
安装步骤 切换至root su 安装依赖库 sudo apt-get install build-essential && sudo apt-get install libtool s ...
- quartus在线调试的方法
quartus在线调试的方法 在Quartus II Version 7.2 Handbook Volume 3: Verification中的Section V. In-System Design ...
- 在UTF-8页面中引入编码为GBK的JavaScript文件乱码问题了
原文地址:http://js8.in/2009/12/11/%E5%AF%B9%E5%BC%95%E7%94%A8%E5%A4%96%E9%83%A8javascript%E9%A1%B5%E9%9D ...
- jvm(2):垃圾收集和内存分配
typora-root-url: ./ 垃圾收集 垃圾收集器关注的是线程共享的这部分内存. jvisualvm用来监控JVM的运行情况,可以用它来查看和浏览Heap Dump.Thread Dump. ...
- 微信或QQ屏蔽了我的域名,已经被微信屏蔽的域名如何在微信打开,如何进行微信域名防封?
微信域名完全防封是绝对不可能的,这是必须明确的,曾经有人打折<不死域名>的概念,它不是不死,是稍微命长一点,在推广上成本更低一下,效果更好一些, 主要的技术原理是利用了腾讯云的域名安全联盟 ...
- Django_模板
1. 模板变量 小插曲 2. 模板点语法和标签 2.1 获取属性 2.2 调用方法 2.3 获取索引 2.4 获取字典中的值 3. 模板中的标签 3.1 if 3.2 for 3.3 注释 乘除 整除 ...
- 如何预测股票分析--自动ARIMA
在上一篇中,我们发现knn和线性回归一样,表现的不是特别好,来看看时间序列的表现 时间序列预测法其实是一种回归预测方法,属于定量预测,其基本原理是;一方面承认事物发展的延续性,运用过去时间序列的数据进 ...
- ListVIew中包含水平滑动控件,左右滑动时容易触发上下滑动
自定义ListView import android.content.Context;import android.util.AttributeSet;import android.view.Moti ...
- c/c++学习01
c++指针初始赋值: //指针初始赋值 int* a = new int(3); //第二种赋值 int 初始值 = 100; int *b = &初始值; //由new分配的内存块通常使用过 ...
- 树莓派学习之路-GPIO Zero
原来用的都是RPi.GPIO模式开发,写程序 今天看到了GPIOZERO的资料,觉得这个API还是很好用的, 唯一的缺点就是官方资料是英文的,而且目前这方面的资料也不多, 所以开始写这篇博文,将自己学 ...