DataGridView does not display data in ToolStripDropDown

I use the code provided by Jesper Palm here: Make the user control display out of the box

/// <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 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 PictureBox showing its info. But for some reason, I cannot get the DataGridView to display anything when it is in a popup.

If I pulled out a grid from a popup, it will display all its information in order. If I pause during debugging, the grid shows that it has all the data. It just doesn't display anything.

Does anyone have any ideas?

+4
source share
2 answers

I could not reproduce your problem. Can you provide more code? I tested VS2010 RC (.NET 4) and VS2008 (.NET 3.5), and this code works in both:

 public partial class Form1 : Form { public class Person { public string FirstName { get; set; } public string LastName { get; set; } public string PhoneNumber { get; set; } } List<Person> _People; public Form1() { InitializeComponent(); _People = new List<Person>(); _People.Add(new Person() { FirstName = "John", LastName = "Smith", PhoneNumber = "123-456-7890" }); _People.Add(new Person() { FirstName = "Jane", LastName = "Doe", PhoneNumber = "098-765-4321" }); } private void Form1_Load(object sender, EventArgs e) { pictureBox1.Image = Image.FromFile("barcode.png"); pictureBox1.Location = new Point(-1000, -1000); dataGridView1.DataSource = _People; dataGridView1.Location = new Point(-1000, -1000); } private void button1_Click(object sender, EventArgs e) { PopupControl popup = new PopupControl(pictureBox1); popup.Show(new Point(this.Location.X - 128, this.Location.Y)); } private void button2_Click(object sender, EventArgs e) { PopupControl popup = new PopupControl(dataGridView1); popup.Show(new Point(this.Location.X - 128, this.Location.Y)); //optionally change the items in the data source _People.Add(new Person() { FirstName = "NewFirst", LastName = "NewLast", PhoneNumber = "123-333-3322" }); //reset the bindings bindingSource1.DataSource = _People; bindingSource1.ResetBindings(true); } } 

Here's what it looks like: alt text http://img534.imageshack.us/img534/1640/popupcontrolwithgrid.jpg

In the designer, you must configure the BindingSource and assign it as a DataGridView DataSource.

+1
source

Perhaps this is a problem with the pattern. Maybe you could try .Refresh on a popup container or grid after it has been shown?

0
source

Source: https://habr.com/ru/post/1303903/


All Articles