Note that there are some explanatory texts on larger screens.

plurals
  1. POPutting Values in Controls when dynamically creating a form
    primarykey
    data
    text
    <p>I have been working on an issue for a while and I finally figured it out. I was trying to set a control when the Form is being initialize. I am thinking that the control's value isn't being set is because the control has been drawn yet (CORRECT ME IF I AM WRONG). </p> <p>My partial form code</p> <pre><code>//in form 1 .... private void button2_Click(object sender, EventArgs e) { Form2 form = new Form2(); form.Owner = this; form.Show(this); } ....} public Form2() { InitializeComponent(); setData(); //Sets a datagridview's combobox column and databinds a datatable setGrid(); //Sets each row in the datagridview combobox's value to a string } private void setData() { gvTest.AllowUserToAddRows = false; string strConn = "server=10.253.3.185;database=petersun-test1;user id=ctore;password=cqi$$;connection timeout=30"; SqlConnection conn = new SqlConnection(strConn); DataTable dit = new DataTable(); try { conn.Open(); string sql = "SELECT LTRIM(RTRIM(COLUMN_NAME)) as ColumnName from INFORMATION_SCHEMA.COLUMNS where Table_Name='coproc' order by ORDINAL_POSITION"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dit); DataGridViewComboBoxColumn dcDatabasefields = new DataGridViewComboBoxColumn(); dcDatabasefields.DataPropertyName = "ColumnName"; dcDatabasefields.HeaderText = "Database Field Name"; dcDatabasefields.Name = "dbFields"; dcDatabasefields.DisplayMember = "ColumnName"; dcDatabasefields.ValueMember = "ColumnName"; dcDatabasefields.Width = 200; BindingSource bsourceFields = new BindingSource(); bsourceFields.DataSource = dit; dcDatabasefields.DataSource = bsourceFields; dcDatabasefields.DataSource = dit; // bsourceFields; gvTest.Columns.Add(dcDatabasefields); } finally { conn.Close(); } DataTable dt = new DataTable(); DataColumn dc = new DataColumn("options"); dt.Columns.Add(dc); DataRow dr = dt.NewRow(); dr["options"] = "A"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["options"] = "C"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["options"] = "D"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["options"] = "E"; dt.Rows.Add(dr); gvTest.DataSource = dt; } private void setGrid() { foreach(DataGridView Row in gvGrid.Rows) { Row.Cells[0].Value = "string"; } } </code></pre> <p>So what I think is happening is: 1. The component is getting initialized 2. Creates the datagridview with columns 3. Sets the column values 4. Draws the form</p> <p>Is my thinking correct? My question is what form event should I set the control's value? I did some research and I am thinking on the PAINT event, but I am not sure either. Could someone explain the Form's life cycle in some detail or point me to somewhere. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload