0

I have a checkedlistbox and when i populate it i want to have an empty space between each check box. i can create them with an empty string but the check box is still there. can anyone please help me.

thank you

tironci
  • 217
  • 1
  • 5
  • 19
  • 1
    Can you show the HTML that is causing the problem? – Fenton Jun 03 '10 at 15:43
  • 1
    Clarify: you want empty space *vertically* between each row that contains a check box? – JYelton Jun 03 '10 at 15:43
  • 1
    Missing some important info. Are you using WPF, ASP, ...? – mamoo Jun 03 '10 at 15:44
  • @Sohnee, this isn't HTML – JYelton Jun 03 '10 at 15:44
  • Correct your grammar then explain the problem in detail. – mcandre Jun 03 '10 at 15:49
  • The first question that I would ask is why you need a space between elements. There may be a better way to solve that problem. The only way I can think of to include spaces between elements in a CheckedListBox is to implement a custom version of the control yourself, or possibly override the paint method, neither of which I'd recommend. – Mike Burton Jun 03 '10 at 15:54
  • @JYelton - well, the question really could tell us if it's ASP.NET, WPF or WinForms. There just isn't enough information. – Fenton Jun 04 '10 at 07:21

1 Answers1

2

Assuming you are using .NET C# winforms...

You can inherit this control, and override the property .ItemHeight as follows:

private class OverriddenCheckedListBox : CheckedListBox
{
    public override int ItemHeight { get; set; }
}

Place one of these controls on your form, and set the property to a height that suits the amount of space you desire. (If you want it to show up in the toolbox you'll need to create it as a user control.) Here is an example:

OverriddenCheckedListBox ochkListBox = new OverriddenCheckedListBox();
ochkListBox.Location = new Point(0, 0);
ochkListBox.Dock = DockStyle.Fill;
ochkListBox.Items.Add("Alpha");
ochkListBox.Items.Add("Beta");
ochkListBox.Items.Add("Charlie");
ochkListBox.Items.Add("Delta");
ochkListBox.Items.Add("Epsilon");
ochkListBox.ItemHeight = 30; // This is your row height
this.Controls.Add(ochkListBox);
JYelton
  • 35,664
  • 27
  • 132
  • 191
  • thank you for your reply. but this creates a new checkedlistbox, is there a way i can make them show up on the checkedlistbox i created? also the height property does not seem to work. – tironci Jun 03 '10 at 19:08
  • I want to add empty spaces vertically in between check boxes. – tironci Jun 03 '10 at 19:53