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 ...
随机推荐
- UI 自定义布局
今天继续学习UI布局的布局管理器,昨天学习并练习使用了线性布局,相对布局和帧布局,今天学习表格布局,网格布局以及嵌套布局,相对于前三种布局,后三种布局比较复杂一些. 1.表格布局 TableLayou ...
- codeforce D. White Lines
二维前缀和 给你一个n*n的矩阵,里面有两种字符,‘W’和‘B’,代表black 和white .其实这个矩阵就是一个方形画板,你有一个k*k的橡皮只能用一次,使k*k的矩阵里的B变成W,问完全空白的 ...
- 开源镜像站,vmware下载
vmware下载:https://www.newasp.net/soft/345086.html 官网下载链接:https://www.centos.org/download/ http://mirr ...
- (转)多进程 & 多线程的区别与适用场景
转自:http://www.cnblogs.com/huntfor/p/4021327.html 关于多进程和多线程,教科书上最经典的一句话是“进程是资源分配的最小单位,线程是CPU调度的最小单位”, ...
- 美化传奇NPC对话框添加图片显示实列
NPC对话框一般都是文字显示,有些GM想突出版本特色,在NPC对话框加些专业图片,彰显独特之处,其实这是很简单的.下面为你讲解美化传奇NPC对话框添加图片显示实列 我们要添加你要放入npc图片的补丁. ...
- java项目连接Oracle配置文件
转载自:https://blog.csdn.net/shijing266/article/details/42527471 driverClassName=oracle.jdbc.driver.Ora ...
- mysql渗透过程
1 打开目标站点:www.xxx.com 2 注册账号并登录,大概找下注入点,没找到 3 用namp -A -T4 目标站点扫描开放的服务 发现mysql等 4 猜弱口令 + 字典 对mysql进行 ...
- 给Python初学者的一些编程技巧
展开这篇文章主要介绍了给Python初学者的一些编程技巧,皆是基于基础的一些编程习惯建议,需要的朋友可以参考下交换变量 x = 6y = 5 x, y = y, x print x>>&g ...
- TCP的状态转换
TCP的状态转换图 手写的状态转换图 一.服务端状态变迁: 服务端创建套接字之后调用listen函数将套接字有一个未连接的主动套接字转换为被动套接字,指示内核应接受指向该套接字的连接请求,套接字状态 ...
- no module named系列问题解决
持续更新中~~~ 1.终端指令错误:no module named 'gdbm' 解决办法: sudo apt-get install python3.6-gdbm 2.终端无法定位软件包 解决办法: ...