public void AddOrUpdatePushItem(PushSubscription p, ListViewItem lvi = null) { if (lstPushSubscriptions.InvokeRequired) { AddOrUpdatePushItemCallback cb = new AddOrUpdatePushItemCallback(AddOrUpdatePushItem); this.Invoke(cb, new object[] { p, lvi }); } else { lstPushSubscriptions.BeginUpdate(); try { if (lvi == null) { // No ListViewItem given, try to find a matching row foreach (ListViewItem lvi_candidate in lstPushSubscriptions.Items) { if (p.getId() == ((PushSubscription)lvi_candidate.Tag).getId()) { lvi = lvi_candidate; break; } } } if (p.isDeleted()) { if (lvi != null) { lstPushSubscriptions.Items.Remove(lvi); } } else { if (lvi == null) { // Still not found it, add it lvi = lstPushSubscriptions.Items.Add(p.getName()); lvi.SubItems.Add(p.getCreatedAt().ToString()); lvi.SubItems.Add(p.getStatus()); lvi.SubItems.Add(p.getOutputType()); lvi.SubItems.Add(p.getLastRequest().ToString()); lvi.SubItems.Add(p.getLastSuccess().ToString()); } else { // Already exists, update the pieces lvi.SubItems[0].Text = p.getName(); lvi.SubItems[1].Text = p.getCreatedAt().ToString(); lvi.SubItems[2].Text = p.getStatus(); lvi.SubItems[3].Text = p.getOutputType(); lvi.SubItems[4].Text = p.getLastRequest().ToString(); lvi.SubItems[5].Text = p.getLastSuccess().ToString(); } // Store the Push subscription in the item lvi.Tag = p; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } lstPushSubscriptions.EndUpdate(); } }
public void AddOrUpdatePushItem(PushSubscription p, ListViewItem lvi = null) { if (lstPushSubscriptions.InvokeRequired) { AddOrUpdatePushItemCallback cb = new AddOrUpdatePushItemCallback(AddOrUpdatePushItem); this.Invoke(cb, new object[] { p, lvi }); } else { lstPushSubscriptions.BeginUpdate(); try { if (lvi == null) { // No ListViewItem given, try to find a matching row foreach (ListViewItem lvi_candidate in lstPushSubscriptions.Items) { if (p.getId() == ((PushSubscription)lvi_candidate.Tag).getId()) { lvi = lvi_candidate; break; } } } if (p.isDeleted()) { if (lvi != null) { lstPushSubscriptions.Items.Remove(lvi); } } else { if (lvi == null) { // Still not found it, add it lvi = lstPushSubscriptions.Items.Add(p.getName()); lvi.SubItems.Add(p.getCreatedAt().ToString()); lvi.SubItems.Add(p.getStatus()); lvi.SubItems.Add(p.getOutputType()); lvi.SubItems.Add(p.getLastRequest().ToString()); lvi.SubItems.Add(p.getLastSuccess().ToString()); } else { // Already exists, update the pieces lvi.SubItems[0].Text = p.getName(); lvi.SubItems[1].Text = p.getCreatedAt().ToString(); lvi.SubItems[2].Text = p.getStatus(); lvi.SubItems[3].Text = p.getOutputType(); lvi.SubItems[4].Text = p.getLastRequest().ToString(); lvi.SubItems[5].Text = p.getLastSuccess().ToString(); } // Store the Push subscription in the item lvi.Tag = p; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } lstPushSubscriptions.EndUpdate(); } }