第一种方法:

dataGridFirst.PreparingCellForEdit += new EventHandler<DataGridPreparingCellForEditEventArgs>(dataGridFirst_PreparingCellForEdit);void dataGridFirst_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e){Suppose this list(get and set values)//var myValue = dataGrid1.SelectedItem[0].ToString(); ClientsList selectedrow = ClientsList)dataGridFirst.SelectedItem;string Clientname = selectedrow.Name;int Clientid = selectedrow.ClientID;}

第二种方法:

private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) {     DataGrid dataGrid = sender as DataGrid;  if (e.AddedItems!=null && e.AddedItems.Count>0)  {       // find row for the first selected item     DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]);    if (row != null)   {          DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);   // find grid cell object for the cell with index 0       DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(0) as DataGridCell;      if (cell != null)     {             Console.WriteLine(((TextBlock)cell.Content).Text);         }     }   }}static T GetVisualChild<T>(Visual parent) where T : Visual{ T child = default(T);int numVisuals = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; 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;}

转载于:https://www.cnblogs.com/wangsu/archive/2013/01/08/WPF_DataGrid_Cell.html

WPF DataGrid 对行中单元格的访问相关推荐

  1. WPF DataGrid通过点击单元格获取所在的行号

    WPF DataGrid通过点击单元格获取所在的行号 private void DataGridCell_MouseDoubleClick(object sender, MouseButtonEven ...

  2. EduCoder-Web程序设计基础-html5-表格基本结构-第4关:表格中单元格样式的设置

    目录 任务描述 相关知识 编程要求 测试说明 代码示例 任务描述 本关任务:编写一个两行两列的表格网页,表格中的单元格样式进行设置.效果如下图所示: 表格效果3 相关知识 为了完成本关任务,你需要掌握 ...

  3. Excel技能树系列02:公式中单元格的绝对引用、相对引用和混合引用

    这是Excel技能树系列的第二篇,正式开始Excel技能树知识的讲解了.如果对电子表格的起源和发展感兴趣,可以查看已经发布的Excel技能树系列01篇.本系列写给想要进阶的高频电子表格用户,本系列不适 ...

  4. VBA-Excel中单元格的引用方法

    VBA-Excel中单元格的引用方法 使用VBA对Excel中的单元格或单元格区域进行选择有很多种方法,可以归结为两大类: 使用行列数进行选择 根据已经选择的单元格(区域)进行再选择 1.使用rang ...

  5. Python处理Excel表中单元格带有换行的数据

    Python处理Excel表中单元格带有换行的数据 文章目录 Python处理Excel表中单元格带有换行的数据 问题样式 实例问题 实例实现代码 实例结果 问题样式 在数据处理过程中常常会遇到这样一 ...

  6. Aspose.Words for .NET使用表格教程之水平和垂直合并表格中单元格

    Aspose.Words For .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsof ...

  7. EasyUI Datagrid 鼠标悬停显示单元格内容 复制代码

    EasyUI Datagrid 鼠标悬停显示单元格内容 第一种方式: 1.js 定义函数<script type="text/javascript"> //格式化单元格 ...

  8. php 中如何设置单元格跨行,HTML表格中单元格跨行跨列

    HTML表格中单元格跨行跨列 对于标准的表格,每一行的单元格 数量是一样的.但在实际使用中,经常会遇到跨行跨列的表格,这个时候,每一行的数量就不一样了. 一.定义 所谓"跨行",是 ...

  9. 表格中单元格之间分隔线的隐藏方法

    表格中单元格之间分隔线的隐藏方法 第 一 行 第 二 行 第 三 行 这个表格去掉了单元格之间的纵向分隔线 第 第 第 一 二 三 列 列 列 这个表格去掉了单元格之间的横向分隔线 横   线 竖   ...

最新文章

  1. STM32固件库文件树及构成详解
  2. MATLAB-矩阵相关计算(1)
  3. 牛客网在线编程之“字符串分割”
  4. 导致UPS蓄电池损坏的原因有哪些?
  5. 内存溢出_关于PermGen Space内存溢出解决方案
  6. 第三章 阴阳的工作机制(1)
  7. 一个前端的10年前端职业路
  8. 【LeetCode】【refine 2】题号:*2. 两数相加
  9. RNN LSTM GRU Attention transformer公式整理总结(超详细图文公式)
  10. 比Everything、listary、DocFetcher还好用的桌面文档搜索软件 - bbdoc
  11. 目标跟踪论文整理(不全,以单目标为主)
  12. 依赖、关联、聚合、组合
  13. java 兑换码生成_java生成兑换码礼包码--工具类
  14. SolidWorks如何编辑今日制造插件生成的齿轮
  15. css td边框重复,表格线边框重复css解决方法
  16. 你离年薪50w的架构师还差多远
  17. 侠客行:一技压身,天下行走
  18. Adobe InDesign CS5
  19. java分词 词权重_分析牛:查询分词权重,巧妙布局网页关键词
  20. java.io.IOException: unexpected end of stream on https://xxx.xxx.xxx.xxx:84/

热门文章

  1. centOS下安装tomcat详解
  2. org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
  3. 新装WIN7 UPDATE 无法更新
  4. Use Amazon VM to try Openstack (1) (with DevStack)
  5. Part4:Citrix 3D 技术Step by Step配置指导手册
  6. meta 标签的详细使用
  7. 用css sprites(图像拼合技术)优化css加快网站速度[转]
  8. Win10 Qt5安装
  9. 微服务链路追踪_.NET Core微服务:分布式链路追踪系统分享
  10. Amber Group散户投资APP资管规模超10亿美元