Dynamically Added Control

  • Thread starter Thread starter _asgar
  • Start date Start date
A

_asgar

Guest
I am dynamically adding TextBoxes in Itemcheck eventhandker method.The textbox is added next to checked item in a checkedlistbox.All is running fine except when i scroll the textbox next to the checked item loses its position(Location).

here is the code

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if(e.NewValue == CheckState.Checked)
{
var ch = (CheckedListBox)sender;
TextBox tb = new TextBox();
tb.Name = "textBox" + (e.Index + 1).ToString();
int y = ch.GetItemHeight(e.Index) * (e.Index);
Point p = new Point(200, y);
tb.Height = ch.GetItemHeight(e.Index);
tb.Width = 150;
tb.Location = p;
checkedListBox1.Controls.Add(tb);
}
else if(e.NewValue == CheckState.Unchecked)
{
checkedListBox1.Controls.RemoveByKey("textBox" + (e.Index +1).ToString());
}

}




Asgar

Continue reading...
 
Back
Top