WPF中datagrid控件选中单元格变色或编辑单元格后变色
来源:互联网 发布:小说整站源码带采集 编辑:程序博客网 时间:2024/05/16 09:25
不多说,直接上代码~~~
//事件 :编辑单元格后,让单元格变色,以便提醒用户,该单元格数据曾经做过修改
private void dgSourceData_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
int colindex = -1;
int rowindex = -1;
colindex = this.dgSourceData.CurrentCell.Column.DisplayIndex;//获取选中单元格列号
rowindex = this.dgSourceData.SelectedIndex;//获取选中单元格行号
DataGridRow row = (DataGridRow)dgSourceData.ItemContainerGenerator.ContainerFromIndex(rowindex);//获取选中单元格所在行
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);//函数调用,获取行中所有单元格的集合
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(colindex);//锁定选中单元格(重点)
if (cell != null)
{
dgSourceData.ScrollIntoView(row, dgSourceData.Columns[colindex]);
cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(colindex);
cell.Focus();
cell.Background = new SolidColorBrush(Colors.Red);//OK!问题解决,选中单元格变色
}
}
//获取行中所有单元格集合的函数
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;
}
- WPF中datagrid控件选中单元格变色或编辑单元格后变色
- silverlight中DataGrid单元格变色问题
- (备忘)关于Flex4中DataGrid单元格变色处理
- DataGrid单元格移动变色,点击变色,双击取消颜色,排序.
- DataGrid单元格移动变色,点击变色,双击取消颜色,排序.
- DataGrid单元格移动变色,点击变色,双击取消颜色,排序.
- DataGrid单元格移动变色,点击变色,双击取消颜色,排序.
- DataGrid单元格移动变色,点击变色,双击取消颜色,排序.
- DataGrid单元格移动变色,点击变色,双击取消颜色,排序
- Excel单元格自动变色
- Extjs4 单元格变色
- 单元格变色和图片透明
- asp单元格或者字段变色
- DEV pivotGridControl 单元格内容变色
- winform gridview表行、单元格变色
- grid 单元格和行变色
- WPF:获取DataGrid控件单元格DataGridCell
- WPF DataGrid合并单元格
- Mysql 和 Postgresql 对比
- “千金”原指出类拔萃男子 比喻女孩始于元代
- 让复制构造函数简单起来
- 多线程应用程序设计
- 用SecureCRT连接VMware中的Linux系统
- WPF中datagrid控件选中单元格变色或编辑单元格后变色
- extjs4中的checkboxgroup 重写
- How to use Microsoft Dynamics Connector to sync data between different crm organizations
- MySQL与PostgreSQL的大表处理性能比较
- IOS 长按显示圆形菜单
- JavaScript的变量
- mysql相关
- PDCA理念融入软件测试
- C++ 中char* ,String ,int , CString之间的转换