public AttributeSelectionForm(UpdateImageAttributesDelegate updateAttributes, CrmOrganization org, CrmAttribute[] attributeList, Collection <string> currentValue, bool currentAllChecked) { if (org == null) { throw new ArgumentNullException("org"); } else if (attributeList == null) { throw new ArgumentNullException("attributeList"); } else if (updateAttributes == null) { throw new ArgumentNullException("updateAttributes"); } InitializeComponent(); m_org = org; m_updateAttributes = updateAttributes; //Create a sorter for the listview. This will allow the list to be sorted by different columns lsvAttributes.ListViewItemSorter = new ListViewColumnSorter(0, lsvAttributes.Sorting); m_attributesList = new List <ListViewItem>(); foreach (var attribute in attributeList) { var item = new ListViewItem { Name = attribute.LogicalName.Trim().ToLowerInvariant(), Text = attribute.FriendlyName, ImageIndex = 0 }; item.SubItems.Add(attribute.LogicalName); item.SubItems.Add(attribute.TypeName == "MultiSelectPicklistType" ? "MultiSelect Picklist" : attribute.Type.ToString()); item.Tag = attribute; item.Checked = currentAllChecked || currentValue.Contains(item.Name); var addattribute = false; switch (attribute.Type) { case AttributeTypeCode.Boolean: case AttributeTypeCode.Customer: case AttributeTypeCode.DateTime: case AttributeTypeCode.Decimal: case AttributeTypeCode.Double: case AttributeTypeCode.Integer: case AttributeTypeCode.Lookup: case AttributeTypeCode.Memo: case AttributeTypeCode.Money: case AttributeTypeCode.Owner: case AttributeTypeCode.PartyList: case AttributeTypeCode.Picklist: case AttributeTypeCode.State: case AttributeTypeCode.Status: case AttributeTypeCode.String: { addattribute = true; } break; case AttributeTypeCode.CalendarRules: case AttributeTypeCode.Uniqueidentifier: case AttributeTypeCode.Virtual: if (attribute.IsPrimaryId || attribute.TypeName == "MultiSelectPicklistType") { addattribute = true; } break; } if (addattribute) { m_attributesList.Add(item); } } }
public AttributeSelectionForm(UpdateImageAttributesDelegate updateAttributes, CrmOrganization org, CrmAttribute[] attributeList, Collection <string> currentValue, bool currentAllChecked) { if (org == null) { throw new ArgumentNullException("org"); } else if (attributeList == null) { throw new ArgumentNullException("attributeList"); } else if (updateAttributes == null) { throw new ArgumentNullException("updateAttributes"); } InitializeComponent(); m_org = org; m_updateAttributes = updateAttributes; //Create a sorter for the listview. This will allow the list to be sorted by different columns lsvAttributes.ListViewItemSorter = new ListViewColumnSorter(0, lsvAttributes.Sorting); foreach (CrmAttribute attribute in attributeList) { switch (attribute.Type) { case AttributeTypeCode.Boolean: case AttributeTypeCode.Customer: case AttributeTypeCode.DateTime: case AttributeTypeCode.Decimal: case AttributeTypeCode.Double: case AttributeTypeCode.Integer: case AttributeTypeCode.Lookup: case AttributeTypeCode.Memo: case AttributeTypeCode.Money: case AttributeTypeCode.Owner: case AttributeTypeCode.PartyList: case AttributeTypeCode.Picklist: case AttributeTypeCode.State: case AttributeTypeCode.Status: case AttributeTypeCode.String: { ListViewItem item = lsvAttributes.Items.Add(attribute.LogicalName.Trim().ToLowerInvariant(), attribute.FriendlyName, 0); item.SubItems.Add(attribute.LogicalName); item.SubItems.Add(attribute.Type.ToString()); item.Tag = attribute; } break; case AttributeTypeCode.CalendarRules: case AttributeTypeCode.Uniqueidentifier: case AttributeTypeCode.Virtual: if (attribute.IsPrimaryId) { ListViewItem item = lsvAttributes.Items.Add(attribute.LogicalName.Trim().ToLowerInvariant(), attribute.FriendlyName, 0); item.SubItems.Add(attribute.LogicalName); item.SubItems.Add(attribute.Type.ToString()); item.Tag = attribute; } continue; } } if (currentAllChecked) { chkSelectAll.Checked = true; foreach (ListViewItem item in lsvAttributes.Items) { item.Checked = true; } } else if (currentValue != null && currentValue.Count != 0) { foreach (string value in currentValue) { if (!string.IsNullOrEmpty(value) && lsvAttributes.Items.ContainsKey(value.Trim().ToLowerInvariant())) { lsvAttributes.Items[value.ToLowerInvariant()].Checked = true; } } } }