开发者

Adding DataGrid to a GUI form via a separate class

开发者 https://www.devze.com 2023-01-24 08:39 出处:网络
I have code similar to: public datagridview dg = new datagridview(); //populate grid. Fo开发者_StackOverflow中文版rm1 GUI = new Form1();

I have code similar to:

public datagridview dg = new datagridview();
//populate grid.

Fo开发者_StackOverflow中文版rm1 GUI = new Form1();

_dgv.Location = new System.Drawing.Point(0, 50);
_dgv.Size = new System.Drawing.Size(630, 200);
GUI.splitContainer1.Panel2.Controls.Add(_dgv);

This I was hoping, would place the datagridview on the GUI WinForm, but nothing shows up.

Any ideas?


Have you made sure the splitContainer1 is appropriately placed and sized? If it's too small, perhaps the DataGridView is located outside it's container (splitContainer1).


Set the parent of the dgv to be the panel:

Form1 GUI = new Form1();
        _dgv.Parent = GUI.splitContainer1.Panel2;
        _dgv.Location = new System.Drawing.Point(0, 50); 
        _dgv.Size = new System.Drawing.Size(630, 200);

I know this theoretically does the same thing, but it works for me

0

精彩评论

暂无评论...
验证码 换一张
取 消