i created a class derived from CheckedListBox so i can change item height
as this:
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class ExpandableChecked : CheckedListBox
{
public ExpandableChecked()
: base()
{
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override int ItemHeight
{
get;
set;
}
}
- everything is alright except for changing the control height in the designer
- when i try to stretch its width or moving is great but stretch the height is giving this error message:
Attempted to divide by zero
whats wrong with it?
update: can i also add the itemHeight property to the properties window ??
This goes wrong because of the IntegralHeight property, it defaults to True. With that set, the control ensures that the height is always a multiple of the item height so no partial items are visible. It does so by dividing the ClientSize.Height by the ItemHeight.
Trouble is, you overrode the ItemHeight property and don’t initialize it at all. It will default to zero. So this division is going to bomb on a DivideByZeroException.
It is very unclear on how you intend to use this overridden property and why you override it at all. Start by setting IntegralHeight to False in the constructor as one workaround.