Shaitan00 Posted December 29, 2003 Posted December 29, 2003 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? Quote
*Experts* Bucky Posted December 29, 2003 *Experts* Posted December 29, 2003 You forgot to set the grid's Size property. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Shaitan00 Posted December 30, 2003 Author Posted December 30, 2003 : // 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"? Quote
*Experts* Bucky Posted December 30, 2003 *Experts* Posted December 30, 2003 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(); Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.