private void FillData() { lvGrid.Items.Clear(); var no = 0; foreach (var entity in entities.Entities) { var item = lvGrid.Items.Add((++no).ToString()); item.SubItems.Add(entity.Id.Equals(Guid.Empty) ? "" : entity.Id.ToString()); foreach (var column in columns) { var col = column.Key; var valuestr = ""; if (entity.Contains(col)) { var value = entity[col]; if (value != null) { try { if (form.currentSettings.gridFriendly) { valuestr = EntitySerializer.AttributeToString(value, column.Value.Metadata); } else { var basevalue = EntitySerializer.AttributeToBaseType(value); valuestr = basevalue != null?basevalue.ToString() : ""; } } catch { MessageBox.Show("Attribute " + col + " failed"); } } } if (string.IsNullOrEmpty(valuestr)) { valuestr = "<null>"; } item.SubItems.Add(valuestr); } } lvGrid.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }
private static string GetFormattedValue(Entity entity, IOrganizationService service, string attribute, string format) { if (!entity.Contains(attribute)) { return(string.Empty); } var value = entity[attribute]; var metadata = MetadataHelper.GetAttribute(service, entity.LogicalName, attribute, value); if (EntitySerializer.AttributeToBaseType(value) is DateTime dtvalue && (dtvalue).Kind == DateTimeKind.Utc) { value = dtvalue.ToLocalTime(); } if (!ValueTypeIsFriendly(value) && metadata != null) { value = EntitySerializer.AttributeToString(value, metadata, format); } else { value = EntitySerializer.AttributeToBaseType(value).ToString(); } return(value.ToString()); }