public void Add(object item)
        {
            if (item == null)
            {
                return;
            }

            ContentRow contentRow = new ContentRow();

            foreach (MemberInfo memberInfo in members)
            {
                switch (memberInfo)
                {
                case FieldInfo fieldInfo:
                {
                    object value = fieldInfo.GetValue(item);
                    contentRow.AddCell(value);
                    break;
                }

                case PropertyInfo propertyInfo:
                {
                    object value = propertyInfo.GetValue(item);
                    contentRow.AddCell(value);
                    break;
                }
                }
            }

            DataGrid.Rows.Add(contentRow);
        }
Example #2
0
        public DataGridBuilderFromDataTable(DataTable dataTable)
        {
            DataGrid = new DataGrid(dataTable.TableName);

            foreach (DataColumn dataColumn in dataTable.Columns)
            {
                string columnHeader = string.IsNullOrEmpty(dataColumn.Caption)
                    ? dataColumn.ColumnName
                    : dataColumn.Caption;

                DataGrid.Columns.Add(columnHeader);
            }

            foreach (System.Data.DataRow dataRow in dataTable.Rows)
            {
                ContentRow row = new ContentRow(dataRow.ItemArray);
                DataGrid.Rows.Add(row);
            }
        }