Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Given a form [this.] which contains controls [tree, combo boxes, labels, etc].

I want to dynamically add a Datagrid [empty for now] on the form [anywhere, I can place it properly afterwards].

 

:

System.Windows.Forms.DataGrid DGDisplay = new System.Windows.Forms.DataGrid();

DGDisplay.ReadOnly = true;

DGDisplay.Location = new Point(10,10);

this.Controls.Add(DGDisplay);

DGDisplay.Show();

 

However this does not seem to change anything to my Form when run.

Note that no errors are generated.

 

Anyone able to point out my mistake?

  • *Experts*
Posted
You forgot to set the grid's Size property.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted
:

// Display Results

System.Windows.Forms.DataGrid DGDisplay = new System.Windows.Forms.DataGrid();

DGDisplay.ReadOnly = true;

DGDisplay.Location = new Point(100,100);

 

DGDisplay.Size = new Size(100,100);

 

this.Controls.Add(DGDisplay);

DGDisplay.Show();

 

 

Thus I added the Size property however when the code is run nothing appears on the form.

Are there other required properties I am lacking?

Could I be "out of bounds"?

  • *Experts*
Posted

Okay, I added a DataGrid to a form in design mode and looked at

the code generated in the InitializeComponent method. You need

to add calls to BeginInit and EndInit:

 

// Display Results
System.Windows.Forms.DataGrid DGDisplay = new System.Windows.Forms.DataGrid();

((System.ComponentModel.ISupportInitialize)(DGDisplay)).BeginInit();

DGDisplay.ReadOnly = true;
DGDisplay.Location = new Point(100,100);
DGDisplay.Size = new Size(100,100); 

((System.ComponentModel.ISupportInitialize)(DGDisplay)).EndInit();

this.Controls.Add(DGDisplay);
DGDisplay.Show();

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...