feurich Posted October 21, 2003 Posted October 21, 2003 Hi there, Programming is solving problems, when you solve one there are 3 more created. I just created controls on a form at startup. Now i want to redraw the GUI with other controls when a cboBox SelectedIndexChanged event has occured. When I try to clear the controls on the form with ofrmmain.controls.clear() only the 2 static controls are cleared. The ones created in runtime are redrawn.One of the controls cleared is the combobox that changes the GUI. Is there a solution for this problem. I geuss that the controls created at runtime are not in the controls collection of the active form ?? Quote Trust the Universe
*Gurus* divil Posted October 21, 2003 *Gurus* Posted October 21, 2003 Yes, controls created at runtime are present in whatever container they were added to. If you added them to the Controls collection of the form, they will be there. If you added them to the Controls collection of a groupbox, they will be there. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
AlexCode Posted October 21, 2003 Posted October 21, 2003 I think I would make a For Each clause to go thru the controls collection and dispose them. This way I'm shure they'll desapear... :D Quote Software bugs are impossible to detect by anybody except the end user.
feurich Posted October 23, 2003 Author Posted October 23, 2003 do not comply pierpetoetoe HHMM I don't know if I understand this. I have created the controls in a Public sub in a class module. So how do I access the events(like cboIndexSet.Selectedvaluechanged) of those controls created at runtime. I want the GUI to change when a other value is selected in the cboIndexSet combobox. :confused: Quote Trust the Universe
Cywizz Posted October 23, 2003 Posted October 23, 2003 You will have to: a) Create a delegate function - as per relevant combo box event handler b) After you created the control, hook the combo's selected index changed event, to the above delegate (using += in c# or addhandler in vb) c) Add required code into this delegate You can get a lot of info around this topic, from msdn Cheers! Quote Howzit??
AlexCode Posted October 23, 2003 Posted October 23, 2003 And don't forget to declare the controls with the WithEvents clause... Otherwize only the properties will be visible! Quote Software bugs are impossible to detect by anybody except the end user.
Administrators PlausiblyDamp Posted October 24, 2003 Administrators Posted October 24, 2003 You don't need to declare the control WithEvents to use the AddHandler / RemoveHandler commands. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
feurich Posted October 25, 2003 Author Posted October 25, 2003 Hi Guys He guys thanks for the information but eeehh make up your minds :p I think I saw some code on the forum already that attacks this problem. ciao Quote Trust the Universe
feurich Posted October 26, 2003 Author Posted October 26, 2003 Sorry but need some help OK Guys Sorry but I need some help. I thought I saw some code on handling events of controls created at runtime. But I couldn't find it on the forum. Does someone has code that explains that ? GreetZ, Feurich Quote Trust the Universe
AlexCode Posted October 27, 2003 Posted October 27, 2003 Consider it as a simple example... Create a Windows Form named frmMain and add the following code: Dim rt_Button As New Button Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load rt_Button = New Button rt_Button.Location = New System.Drawing.Point(296, 224) rt_Button.Name = "rt_Button" rt_Button.TabIndex = 5 rt_Button.Text = "My RT Button" Me.Controls.Add(rt_Button) AddHandler rt_Button.Click, AddressOf rt_Button_Click End Sub Private Sub rt_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) MsgBox("It works!") End Sub Quote Software bugs are impossible to detect by anybody except the end user.
feurich Posted October 27, 2003 Author Posted October 27, 2003 It works but !! OK thanks it works but now the next problem. The public Sub that draws a new GUI with needs the value of the selected index. I pas that on to the public sub as a parameter ex. Public Sub DrwControls(ByVal TableVal As String, ByVal ofrmMain As Windows.Forms.Form) Code to populate the controls end sub Private Sub cboIndexsetOnChange(ByVal source As Object, ByVal e As System.EventArgs) DrwControls("Library", Me) End Sub When i call the chanegevent from the delegate sub I need the value of the selectedindex. How do I reference this value as a parameter of the delegate sub. Maybe I'm to stupid for this ?? Quote Trust the Universe
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.