Creating objects at Runtime

by cmdolcet69 on 11/1/2007 12:38:00 AM How can I create a dropdown box at runtime? I want my dropdown box to
appear when my user enters the program and the it would load the save
data from an xml file. How can i do this?

 

Re: Creating objects at Runtime

by cfps.Christian on 11/1/2007 3:16:00 PM On Nov 1, 9:38 am, cmdolcet69 <colin_dolce...@hotmail.com> wrote:
> How can I create a dropdown box at runtime? I want my dropdown box to
> appear when my user enters the program and the it would load the save
> data from an xml file. How can i do this?

if you know where you want the drop down and what is going to be in it
I would make its ddl.Visible = false and make it = true when you are
ready for it.

If you MUST dynamically place the drop down then you will: (assuming
this is not ASP.NET in which case you would use DropDownList)
dim cbo as new System.Windows.Forms.ComboBox
'Add items to combo
cbo.Location = new Point([x], [y])
cbo.Name = cboName
Me.Controls.Add(cbo)

 

Re: Creating objects at Runtime

by Phill W. on 11/2/2007 1:10:00 PM cmdolcet69 wrote:

> How can I create a dropdown box at runtime?

In exactly the same way that the Forms Designer does! :-)

No; Seriously. ;-)

Have a look in the "Designer Generated Code" region or the *.designer.vb
file (depending on your version of Visual Basic). These contain the
code that your program runs that creates every control in your program.

Read and Learn ...
(then simplify; /some/ of the code it generates is just /rubbish/).

> I want my dropdown box to appear when my user enters the program and
> then it would load the save data from an xml file.

Dim cb as New ComboBox()

With cb
    .Location = New Point( 0, 0 )
    .Size = New Size( 80, 20 ) ' say
    .Visible = True
    .Items.Add( "X" )
End With

AddHandler cb.SelectedIndexChanged _
    , AddressOf AnyComboBox_SelectedIndexChanged

Me[.container].Controls.add( cb )


(Remember that each Control (and Form) acts as a container for other
Controls placed "on" it).

For the Xml stuff:

Dim doc as New Xml.XmlDocument
doc.Load( "file" )

With cb
    For Each eNode as XmlNode _
    In doc.SelectNodes( "xPath" )
       cb.Items.Add( eNode.GetAttribute( Value ) ) ' say
       If eNode.GetAttribute( "current" ) <> "" Then
          cb.SelectedIndex = cb.Count - 1
       End If
    Next
End With

HTH,
    Phill W.