// Protected methods. /// <summary> /// An event handler called when a new comment has been set. /// </summary> /// <param name="oldComment">The old comment.</param> /// <param name="newComment">The new comment.</param> protected virtual void OnCommentSet(Comment oldComment, Comment newComment) { // If the comment has not changed, do nothinh. if (oldComment == newComment) return; if (null == newComment) { this.labelTitle.Text = "No comment selected"; this.textBoxPublished.Clear(); this.textBoxUpdated.Clear(); this.textBoxAuthor.Clear(); this.textBoxComment.Clear(); this.checkBoxSpam.Checked = false; } else { this.labelTitle.Text = newComment.Title; this.textBoxPublished.Text = newComment.Published != null ? newComment.Published.ToString() : string.Empty; this.textBoxUpdated.Text = newComment.Updated.ToString(); this.textBoxAuthor.Text = newComment.Author != null ? newComment.Author.UserId : string.Empty; this.textBoxComment.Text = newComment.Content != null ? newComment.Content : string.Empty; this.checkBoxSpam.Checked = newComment.Spam; } if (this.Focused) { this.textBoxPublished.Select(); this.textBoxPublished.SelectionStart = 0; this.textBoxPublished.SelectionLength = 0; } }
/// <summary> /// Adds a new comment to the list. /// </summary> /// <param name="comment">The comment.</param> public void Add(Comment comment) { ListViewItem item = new ListViewItem( new string[] { comment.Published != null ? comment.Published.Value.ToString() : comment.Updated.ToString(), comment.Author != null ? comment.Author.UserId : string.Empty, comment.Title }, 0); item.Tag = comment; this.listView.Items.Add(item); }