Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 ??

Trust the Universe
  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
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
Software bugs are impossible to detect by anybody except the end user.
Posted

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:

Trust the Universe
Posted

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!

Howzit??
Posted
And don't forget to declare the controls with the WithEvents clause... Otherwize only the properties will be visible!
Software bugs are impossible to detect by anybody except the end user.
Posted

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

Trust the Universe
Posted

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

Trust the Universe
Posted

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

Software bugs are impossible to detect by anybody except the end user.
Posted

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 ??

Trust the Universe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...