public static string GetCheckedItems(CheckedListBox cblItems) { string resultList = ""; for (int i = 0; i < cblItems.CheckedItems.Count; i++) { if (cblItems.GetItemChecked(i)) { resultList += string.Format("{0},", cblItems.GetItemText(cblItems.Items[i])); } } return resultList.Trim(','); }
public static void SetCheck(CheckedListBox cblItems, string valueList) { string[] strtemp = valueList.Split(','); foreach (string str in strtemp) { for (int i = 0; i < cblItems.Items.Count; i++) { if (cblItems.GetItemText(cblItems.Items[i]) == str) { cblItems.SetItemChecked(i, true); } } } }
private void AddExpectedContent() { string expectedStr = ""; for (int i = 0; i < chckLstMembersToVerify.Items.Count; i++) { if (chckLstMembersToVerify.GetItemChecked(i)) { string typeMember = chckLstMembersToVerify.GetItemText(chckLstMembersToVerify.Items[i]); if (typeMember.StartsWith("\t")) { expectedStr += "<" + typeMember.Trim() + ">\n|"; } } } txtExpectedResult.Text = expectedStr; }
public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e) { Color back_color, fore_color; Rectangle item_rect = e.Bounds; ButtonState state; /* Draw checkbox */ if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) { state = ButtonState.Checked; if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive) state |= ButtonState.Inactive; } else state = ButtonState.Normal; if (ctrl.ThreeDCheckBoxes == false) state |= ButtonState.Flat; Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 13, 13); ControlPaint.DrawCheckBox (e.Graphics, item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y, checkbox_rect.Width, checkbox_rect.Height, state); item_rect.X += checkbox_rect.Right; item_rect.Width -= checkbox_rect.Right; /* Draw text*/ if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { back_color = ColorHighlight; fore_color = ColorHighlightText; } else { back_color = e.BackColor; fore_color = e.ForeColor; } e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), item_rect); e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font, ResPool.GetSolidBrush (fore_color), item_rect, ctrl.StringFormat); if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) { CPDrawFocusRectangle (e.Graphics, item_rect, fore_color, back_color); } }