首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ToolStripDropDown中不显示数据的DataGridView

在ToolStripDropDown中不显示数据的DataGridView
EN

Stack Overflow用户
提问于 2010-03-12 16:06:29
回答 2查看 1.8K关注 0票数 4

我正在使用Jesper Palm在这里发布的代码:Make user control display outside of form boundry

代码语言:javascript
复制
/// <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);
    }
}

我把它翻译成了VB:

代码语言:javascript
复制
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

它与显示其信息的PictureBox一起工作得很好。但是由于某些原因,我无法让DataGridView在弹出窗口中显示任何内容。

如果我将网格从弹出窗口中拉出,它会很好地显示所有信息。如果我在调试过程中暂停,网格会显示其中包含所有数据。它只是没有显示任何东西。

有谁有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-03-13 06:39:23

我不能重现你的问题。你能提供更多的代码吗?我已经在VS2010 RC (.NET 4)和VS2008 (.NET 3.5)上进行了测试,这段代码在这两种环境下都可以工作:

代码语言:javascript
复制
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);
    }
}

它看起来是这样的:alt text http://img534.imageshack.us/img534/1640/popupcontrolwithgrid.jpg

在设计器中,应设置BindingSource并将其分配为DataGridView的DataSource。

票数 1
EN

Stack Overflow用户

发布于 2010-03-13 03:41:35

这可能是一个绘图问题。也许你可以在弹出式容器或网格显示后尝试.Refresh?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2431270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档