I’m utilizing the code posted by Jesper Palm here: Make user control display outside of form boundry
/// <summary>
/// A simple popup window that can host any System.Windows.Forms.Control
/// </summary>
public class PopupWindow : System.Windows.Forms.ToolStripDropDown
{
private System.Windows.Forms.Control _content;
private System.Windows.Forms.ToolStripControlHost _host;
public PopupWindow(System.Windows.Forms.Control content)
{
//Basic setup...
this.AutoSize = false;
this.DoubleBuffered = true;
this.ResizeRedraw = true;
this._content = content;
this._host = new System.Windows.Forms.ToolStripControlHost(content);
//Positioning and Sizing
this.MinimumSize = content.MinimumSize;
this.MaximumSize = content.Size;
this.Size = content.Size;
content.Location = Point.Empty;
//Add the host to the list
this.Items.Add(this._host);
}
}
I’ve translated it to VB:
Public Class PopupWindow
Inherits System.Windows.Forms.ToolStripDropDown
Private _content As System.Windows.Forms.Control
Private _host As System.Windows.Forms.ToolStripControlHost
Public Sub New(ByVal content As System.Windows.Forms.Control)
Me.AutoSize = False
Me.DoubleBuffered = True
Me.ResizeRedraw = True
Me._content = content
Me._host = New System.Windows.Forms.ToolStripControlHost(content)
Me.MinimumSize = content.MinimumSize
Me.MaximumSize = content.MaximumSize
Me.Size = content.Size
content.Location = Point.Empty
Me.Items.Add(Me._host)
End Sub
End Class
It works great with a PictureBox showing its information. But for some reason I cannot get the DataGridView to display anything when it is in the popup.
If I pull the grid out of the popup it displays all of its information fine. If I pause during debug, the grid shows that it has all the data in it. It’s just not displaying anything.
Does anybody have any ideas?
I have not been able to reproduce your problem. Can you provide more code? I’ve been testing in VS2010 RC (.NET 4) and VS2008 (.NET 3.5) and this code works in both:
Here’s what it looks like:
alt text http://img534.imageshack.us/img534/1640/popupcontrolwithgrid.jpg
In the designer, you should setup the BindingSource and assign it as the DataGridView’s DataSource.