获取dataGrid 行


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

using System.Windows.Controls;

using System.Windows.Controls.Primitives;

using System.Windows.Media;

 

namespace Splash.WPF

{

    public static class DataGridPlus

    {

        /// <summary>

        /// 获取DataGrid控件单元格

        /// </summary>

        /// <param name="dataGrid">DataGrid控件</param>

        /// <param name="rowIndex">单元格所在的行号</param>

        /// <param name="columnIndex">单元格所在的列号</param>

        /// <returns>指定的单元格</returns>

        public static DataGridCell GetCell(this DataGrid dataGrid, int rowIndex, int columnIndex)       

        {

            DataGridRow rowContainer = dataGrid.GetRow(rowIndex);

            if (rowContainer != null)

            {

                DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);

                DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);

                if (cell == null)

                {

                    dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[columnIndex]);

                    cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);

                }

                return cell;

            }

            return null;

        }

 

        /// <summary>

        /// 获取DataGrid的行

        /// </summary>

        /// <param name="dataGrid">DataGrid控件</param>

        /// <param name="rowIndex">DataGrid行号</param>

        /// <returns>指定的行号</returns>

        public static DataGridRow GetRow(this DataGrid dataGrid, int rowIndex)       

        {

            DataGridRow rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);

            if (rowContainer == null)

            {

                dataGrid.UpdateLayout();

                dataGrid.ScrollIntoView(dataGrid.Items[rowIndex]);

                rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);

            }

            return rowContainer;

        }

 

        /// <summary>

        /// 获取父可视对象中第一个指定类型的子可视对象

        /// </summary>

        /// <typeparam name="T">可视对象类型</typeparam>

        /// <param name="parent">父可视对象</param>

        /// <returns>第一个指定类型的子可视对象</returns>

        public 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;

        }

    }

}

 

时间: 2025-01-13 21:57:19

获取dataGrid 行的相关文章

Silverlight获取DataGrid选中的行数据

注意触发的事件为:CurrentCellChanged后台代码: /// <summary> /// 获取datagrid当前选中的单元格数据 /// 如果绑定的数据源为实体的话默认选中的当前记录为一条实体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgca

jeecg中datagrid中获取选定行的字段值

datagrid代码如下: <t:datagrid name="orderMainList" checkbox="true" pagination="true" fitColumns="false" title="信息" actionUrl="orderMainController.do?datagrid" idField="id" fit="true

WPF:获取DataGrid控件单元格DataGridCell

转载:http://blog.csdn.net/jhqin/article/details/7645357 /* ---------------------------------------------------------- 文件名称:DataGridPlus.cs 作者:秦建辉 MSN:[email protected] QQ:36748897 博客:http://blog.csdn.net/jhqin 开发环境: Visual Studio V2010 .NET Framework 4

datagrid行编辑如何实现级联?

还是级联的问题,不过这一次,是在datagrid里,那么难度上肯定比form中的级联要高. 但是只要熟练掌握了datagrid的API,问题还是很容易就可以解决的. 关键点在于--editor,关于datagrid实现编辑功能全要靠它. 先实现行编辑 比如在datagrid中要实现某一列可编辑,那么需要在那一列的column中配置editor属性 editor的配置可以只指定type,也就是编辑框的类型,可以是combobox,datebox等easyUI配备的一些类型 若对这些编辑框有额外的属

wpf 获取datagrid中模板中控件

//获取name为datagrid中第三列第一行模板的控件 FrameworkElement item = dataGrid.Columns[3].GetCellContent(dataGrid.Items[0]); DataGridTemplateColumn temp = dataGrid.Columns[3] as DataGridTemplateColumn; //img是模板的name object c= temp.CellTemplate.FindName("img", i

Easyui 去掉datagrid 行的样式,并点击checked 改边行颜色!

--最近客户提出的需求 全选高亮样式太丑,每行选中不需要背景图片颜色,字体变黑色,未选中变灰色. 先把代码和改变后的图片 贴出来. /* 初始化DataFrid数据 */ initDataGrid: function () { var pNumber = 0; var pSize = 10; $('#listBuyer').datagrid({ method: 'post', url: 'PR012_TradeRelationService.ashx?Method=GetPR012_TradeR

easyui获取datagrid选中的ids

//获取datagrid选中的ids,逗号分隔,用于删除或编辑行操作 /* *_MyDataGrid为datagrid文本对象,keyId是业务主键名 */ function getSelectId(_MyDataGrid, _keyId) { var _s = _MyDataGrid.datagrid('getSelections'), _ids = ''; for (var i in _s) { var $id = _s[i][_keyId]; //主键ID if ($id) { _ids

easyui datagrid行合并

easyui datagrid行合并 合并方法 /** * EasyUI DataGrid根据字段动态合并单元格 * 参数 tableID 要合并table的id * 参数 colList 要合并的列,用逗号分隔(例如:"name,department,office"); */ function mergeCellsByField(tableID, colList) { var ColArray = colList.split(","); var tTable =

linux c 获取文件行数

源代码如下: /*获取文件行数*/ int file_wc(const char *filename) { int fd; register int linect = 0; char buf[MAXBSTZE]; int len; char *p = NULL; if(filename) { if((fd = open(filename, O_RDONLY)) < 0) { fprintf(stderr, "open %s\n",strerror(errno)); return