Find row index of control added to TableLayoutPanel
I need to take an action when a control is added to a TableLayoutPanel in Windows Forms. I am handling ParentChanged event of the control to find out if the control is added to a parent(here TableLayoutPanel), but the index I receive is -1. TableLayoutPanel t; private void button1_Click(object sender, EventArgs e) { // this.Text = tableLayoutPanel1.Height.ToString(); t = new TableLayoutPanel(); t.Dock = DockStyle.Fill; //t.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; t.AutoSize = true; //t.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; t.RowStyles.Add(new