wpf 获取DataGrid某一个单元格,设置此单元格ToolTip内容和背景颜色
public void GetCell()
{
for (int i = 0; i < this.datagrid1.Items.Count; i++)
{
DataRowView drv = datagrid1.Items[i] as DataRowView;
DataGridRow row = (DataGridRow)this.datagrid1.ItemContainerGenerator.ContainerFromIndex(i);
if (i == 1)//如果行号等于1
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(1);//获取列号为1
cell.Background = new SolidColorBrush(Colors.Red);
Tooltip tip=new Tooltip();
tip.context="1234";
cell.Tooltip=tip;
}
}
}
public static T GetVisualChild<T>(Visual parent) where T : Visual
{
T childContent = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
childContent = v as T;
if (childContent == null)
{
childContent = GetVisualChild<T>(v);
}
if (childContent != null)
{
break;
}
}
return childContent;
}
//防止在取datagrid的row时出现错误,在Window_Loaded事件里面调用
public void Loed()
{
if (!Window.GetWindow(dataGrid1).IsVisible)
{
Window.GetWindow(dataGrid1).Show();
}
dataGrid1.UpdateLayout();
}
wpf 获取DataGrid某一个单元格,设置此单元格ToolTip内容和背景颜色的更多相关文章
- POI按照源单元格设置目标单元格格式
原文:http://jjw198874.blog.163.com/blog/static/1889845522011102401854234/ POI按照源单元格设置目标单元格格式 poi按照一个源单 ...
- WPF 获取DataGrid 控件选中的单元格信息
获取 DataGrid 选中的单元格的信息DataGridCellInfo cell_Info = this.studentTable.SelectedCells[0]; studentTableIt ...
- wpf 获取datagrid中模板中控件
//获取name为datagrid中第三列第一行模板的控件 FrameworkElement item = dataGrid.Columns[].GetCellContent(dataGrid.Ite ...
- Windows 10设置桌面图标间距、窗口的背景颜色、选中文字的背景颜色
Windows 10取消了“高级外观设置”(或者叫“窗口颜色和外观”设置),想调整一些参数只能进注册表了. 修改后可能需要注销或重启才能生效. 按Win+R,然后输入regedit进入注册表编辑器. ...
- android中设置ListView的选中的Item的背景颜色
ListView中没有默认的选择颜色,只有选择Item后的焦点颜色,鼠标点击时Item有颜色,放开鼠标后颜色也就没有了,要实现放开鼠标后选择项的背景还是有颜色的. 1.配置main.xml <? ...
- wpf 中DataGrid 控件的样式设置及使用
本次要实现的效果为: 这个DataGrid需要绑定一个集合对象,所以要先定义一个Experience类,包含三个字段 /// <summary> /// 定义工作经历类 /// </ ...
- wpf 获取datagrid 模板列中的控件
目前采用的 方法 (网上提供的一款) public static DataGridRow GetRow(DataGrid datagrid, int columnIndex) { ...
- Yii2.0中form->field如何获取主表的一个字段并且设置为只读
<?= $form->field($model, 'last_login_time')->textInput(['readonly' => 'true']) ?>
- 02 uni-app框架学习:设置全局样式统一每个页面的背景颜色
1.设置全局样式可以在App.vue里面 2.在每个页面的根view 里添加一个class名叫page
随机推荐
- Android 进阶 Fragment 介绍和使用 (一)
Fragment概述 Fragment是activity的界面中的一部分或一种行为.你可以把多个Fragment们组合到一个activity中来创建一个多面界面并且你可以在多个activity中重用一 ...
- IIS7.0设置404错误页,返回500状态码
一般在II6下,设置自定义404错误页时,只需要在错误页中选择自定义的页面,做自己的404页面即可.但是在IIS7.0及以上时,设置完404错误页后,会发现状态码返回的是500,并且可能会引起页面乱码 ...
- 慕课网-安卓工程师初养成-4-8 Java循环语句之 do...while
do...while 循环与 while 循环语法有些类似,但执行过程差别比较大. 语法: 执行过程: <1>. 先执行一遍循环操作,然后判断循环条件是否成立 <2>. 如果 ...
- Do less things
就这样,选择做更少的事情,我觉得挺好,至少能睡得很踏实,吃饭很香,也不会觉得难受! 就这样,节制自己的欲望,但是却能很平静,安安静静走自己的路,我觉得生活有希望,也有快乐! 早上,已经可以八点十分起床 ...
- Eclipse User Library Add/Edit/Remove
1:前文 近来开发项目采用的技术是AngularJS+Bootstrap+Spring Boot+SpringMvc+JPA 的方式,创建的项目是 Java Project,对应的JAR文件需要添加到 ...
- button的type属性
今天为看懂一段js代码纠结了很久,搞不明白数据是如何实现post,因为button没有规定属性,其次对submit事件没太搞明白.忽然想起默认属性这个概念,豁然开朗,啊~ 1.请始终为按钮规定 typ ...
- ASP.NET知识集
ASP.NET知识集 编辑删除转载2015-06-23 16:31:55 标签:it //删除指定行数据时,弹出询问对话框 ((LinkButton)(e.Row.Cell[7].Controls[0 ...
- python的文件操作方法
python中的文件对象:文件对象不仅可以用来访问普通的磁盘文件, 而且也可以访问任何其它类型抽象层面上的"文件". 一旦设置了合适的"钩子", 你就可以访问具 ...
- Code Sign error: No unexpired provisioning profiles found that contain any of the keychain's signing certificates
最近离职了,刚好在离职之际有人叫我帮做个项目,简直了,没有mac电脑,没有真ji设备,简直了.接项目那哥们,暂且叫做J,大哥说我给你想办法,then,给借了个mac pro.刚拿到电脑真是喜出望外啊, ...
- win7下无法安装QTP-少了Microsoft Visual c++2005 sp1运行时组件
问题是:当我点击QTP的setup.exe进行QTP安装时,出现提示[少了Microsoft Visual c++2005 sp1运行时组件,安装时会提示命令行选项语法错误,键入“命令/?”可获取帮肋 ...