Пример #1
0
        /// <summary>
        /// 加入DataTable到DetailGrid中
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="dt"></param>
        /// <param name="primaryKeyName"></param>
        /// <param name="setValues"></param>
        public static void AddDetailDataTableRows(this IGrid grid, System.Data.DataTable dt, string primaryKeyName, SetOtherRowValues setValues)
        {
            System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow> masterRows =
                new System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow>();
            foreach (Xceed.Grid.DataRow row in grid.DataRows)
            {
                if (!masterRows.ContainsKey(row.Cells[primaryKeyName].Value.ToString()))
                {
                    masterRows[row.Cells[primaryKeyName].Value.ToString()] = row;
                }
            }

            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Xceed.Grid.DataRow row;
                if (!masterRows.ContainsKey(dt.Rows[i][primaryKeyName].ToString()))
                {
                    row = grid.AddDataRow(dt.Rows[i]);
                    masterRows[dt.Rows[i][primaryKeyName].ToString()] = row;
                }

                MyDetailGrid detailGrid =
                    masterRows[dt.Rows[i][primaryKeyName].ToString()].DetailGrids[0] as MyDetailGrid;
                row = detailGrid.AddDataRow(dt.Rows[i]);

                if (setValues != null)
                {
                    setValues(row);
                }
            }
        }