• 获取DataGrid数据


    获取DataGrid 的表头

    public string[] getCellsDetail(DataGrid dgDetail)
            {
                try
                {
                    string[] strPath=new string[dgDetail.Columns.Count];
                    string path = string.Empty;
                    for (int i = 0; i < dgDetail.Columns.Count; i++)
                    {
                        try
                        {
                            DataGridTextColumn dgcol = dgDetail.Columns[i] as DataGridTextColumn;
                            Binding binding = dgcol.Binding as Binding;
                            path = binding.Path.Path;
                        }
                        catch (Exception lo_ex)
                        {
                            //path = null;
                            continue;
                        }
                        strPath[i] = path;
                    }
                    return strPath;
                }
                catch (Exception lo_Ex)
                {
                    MessageBox.Show("getCellsDetail is Fail," + lo_Ex.Message.Substring(0, 200));
                    return null;
                }
            }
    

      

     取得DataGrid数据

    public DataTable getCheckList(DataGrid dgDetail, DataTable lo_DTabList, string row_name)
            {
                try
                {
                    for (int i = 0; i < dgDetail.Items.Count; i++)
                    {
                        CheckBox lo_SelectCheckBoxInCell = dgDetail.Columns[0].GetCellContent(dgDetail.Items[i]) as CheckBox;
                        if (lo_SelectCheckBoxInCell != null)
                        {
                            if (lo_SelectCheckBoxInCell.IsChecked == true)
                            {
                                //1.整行抓取
                                //DataGridColumn dtcolumn = dgDetail.Columns[i];
                                //lo_DTabList.Rows.Add(dtcolumn);
    
                                DataRow dr = lo_DTabList.NewRow();
                                for (int j = 0; j < lo_DTabList.Columns.Count; j++)
                                {
                                    //((dgDetail.Items[j]) as TextBlock).Text.ToString();
                                    dr[j] = (dgDetail.Columns[j+1].GetCellContent(dgDetail.Items[i]) as TextBlock).Text.ToString();
                                }
                                lo_DTabList.Rows.Add(dr);
    
                                //2.單列抓取,需要傳入列名,如emp_no-> row_name
                                //string ls_row = ((dgDetail.Items[i]) as DataRowView)[row_name].ToString();
                                //lo_DTabList.Rows.Add();
                            }
                        }
                    }
                    if (lo_DTabList.Rows.Count <= 0)
                    {
                        MessageBox.Show("請勾選清單!", ls_TitleName, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                        return null;
                    }
                    return lo_DTabList;
                }
                catch (Exception lo_Ex)
                {
                    MessageBox.Show("getCheckList is Fail," + lo_Ex.Message.Substring(0, 200));
                    return null;
                }
            }
    

      

  • 相关阅读:
    正则表达式
    JS逻辑算法
    js函数
    JS运算符的应用
    JS课堂笔记
    json模块学习
    什么是面向对象,以及如何定义对象,实例化对象
    什么是面向过程,以及代码展示
    什么是元类,以及用type类来产生类.
    python下载安装
  • 原文地址:https://www.cnblogs.com/aDoc/p/12870664.html
Copyright © 2020-2023  润新知