Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey,
I'm using Add-in to create controls dynamically from access form to vb.net form , after loading the design and creating the controls using the add-in I've tried to use textchanged on one of the textboxes and it fires twice even before the form load and on textbox1.text = something ? what the problem would be ?
thank in advance for you help =)
Posted

You change your textbox1.text in more than 1 locations.
C#
1. InitializeComponent();
//------------And other
2. Form_Load() //OR somewhere else
So, TextChanged event fires twice.
 
Share this answer
 
Declare a global variableto count the number of text changes. Increment it in TextChange().

Handle your textchange only when the counter is greater than 2.

Put it in your initializecomponent to see if its called twice.
 
Share this answer
 
Comments
ayat abukhadra 26-Sep-12 3:28am    
I found out whats wrong I'm initiating the .text property when creating the textbox and that causes the firing up for it TextChange function =) ,, thanks for your help =)
How I'm Creating my textbox in my Add-in
1.Load the access control
2.Check if its a text box
3.create a textBox and Call a function called AddTextBox

Private Function AddTextBox(byVal objWindow as EnvDTE.Window, ByVal TextBoxName As String) As TextBox

Dim ObjDesignerHost As IDesignerHost
Dim ObjIComponent As Icomponent
Dim ObjPropertyDescriptor As ProperityDescriptor
Dim TxtBox As TextBox
Dim ObjIComponentInitializer As IComponentInitializer

ObjDesignerHost = DirectCast(ObjWindow.Object , IDesignerHost)
ObjIComponent=ObjDesignerHost.CreateComponent(GetType(TextBox),TextBoxName)
ObjPropertyDescriptor= System.ComponentModel.TypeDescriptor.GetProperties(ObjIComponent).Item("Parent")
ObjPropertyDescriptor.SetValue(ObjIComponent,ObjDesignerHost.RootComponent)
TxtBox=DirectCast(ObjIComponent,TextBox)
ObjIComponentInitializer=TryCast(ObjDesignerHost.GetDesigner(TxtBox),IComponentInitializer)
If(Not ObjIComponentInitializer Is Nothing) Then
ObjIComponentInitializer.InitializeNewComponent(defaultValues:=Nothing)
TxtBox.Text=TextBoxName
Return TxtBox

End Function

Am I doing anything wrong ?
 
Share this answer
 
I've searched the designer code and the form code form a second call to InitializeComponent() my Form code contains nothing except Form1_Load and the textbox_TextChanged and both are empty but my textbox_TextChanged keeps firing twice before the load ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900