Reputation: 49
I created a custom listview
control. I set it to add a new button every time I add a new Column.
When I run the program containing my custom control, the column buttons are placed properly. However, at design time, when I add or remove columns, the control is not updating the added buttons.
They are ok in run-time, but in design time I need to close the form and re-open it (force a re-draw) in order to update the column buttons.
How can I programmatically force a redraw of my User Control?
The Column property looks like this:
<MergableProperty(False)> _
<Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor))> _
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
<Localizable(True)> _
Public ReadOnly Property Columns() As ListView.ColumnHeaderCollection
Get
Return ListView1.Columns
End Get
End Property
And I tried to redraw the control like this:
Me.Invalidate()
Dim x As New Rectangle With {.X = Me.Location.X, .Y = Me.Location.Y, .Size = Me.Size}
Me.NotifyInvalidate(x)
But for some reasons, its not working. In design time, every time Ii add a column, the corresponding button is not added.
Upvotes: 4
Views: 275
Reputation: 71
Just a quick idea, might not be the best solution but it doesn't hurt to try and I'm guessing its going to work even if as I said, it is not the best way to do it.
In the Sub you use for Adding/Remove columns, add the following:
Dim Graphics As Graphics = [yourform].CreateGraphics
Dim ParamArg As New PaintEventArgs(Graphics, [yourform].ClientRectangle)
InvokePaint(Me, ParamArgs)
That shall enforce the nasty thing will paint itself everytime you add/remove.
Upvotes: 1