private void gvAttachmentTypes_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) { if (_curItemButton == null || _pack == null || CurrentLevel == null || !e.Column.Name.StartsWith(AttachmentColNamePrefix)) { return; } SpawnItem item = _curItemButton.Item; string attachmentType = (string)e.Row; int index = int.Parse(e.Column.Name.Replace(AttachmentColNamePrefix, String.Empty)); SpawnItemAttachment[] attachments = item.Attachments.Where(att => att.Type == attachmentType).ToArray(); SpawnItemAttachment attach = index < attachments.Length ? attachments[index] : null; if (e.IsGetData) { if (attach != null) { e.Value = attachments[index].Name; } else { e.Value = null; } } else if (e.IsSetData) { string attachmentName = (string)e.Value; if (attachmentName == null) { if (attach != null) { item.Attachments.Remove(attach); } } else { if (attach != null) { attach.Name = attachmentName; } else { attach = new SpawnItemAttachment(attachmentType, attachmentName); item.Attachments.Add(attach); } } _curItemButton.Refresh(); UpdatePrognosis(); _curItemButton.Refresh(); } }
private void gvItems_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) { if (!_attachTypeColMap.ContainsKey(e.Column)) { return; } string attachmentType = _attachTypeColMap[e.Column]; var item = (Item)e.Row; int index = int.Parse(e.Column.Name.Replace(PackForm.AttachmentColNamePrefix + attachmentType, String.Empty)); SpawnItemAttachment[] attachments = item.Attachments.Where(att => att.Type == attachmentType).ToArray(); SpawnItemAttachment attach = index < attachments.Length ? attachments[index] : null; if (e.IsGetData) { if (attach != null) { e.Value = attachments[index].Name; } else { e.Value = null; } } else if (e.IsSetData) { string attachmentName = (string)e.Value; if (attachmentName == null) { if (attach != null) { item.Attachments.Remove(attach); } } else { if (attach != null) { attach.Name = attachmentName; } else { attach = new SpawnItemAttachment(attachmentType, attachmentName); item.Attachments.Add(attach); } } } }