473,468 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic Controls

I'd like to use the below inherited control that is incorporated into a
CollectionBase to Create controls on a usercontrol.
My question is it possible to copy/clone from the collection of the user
control. When i try to add the control from the collection I am only able
to add one control. See Below BuiltIt. My Solution is to loop through the
collection and set the properties of a new inherited control. This seems
the long way am I missing something?

<System.ComponentModel.DesignTimeVisible(False)> _
Public Class Columns
Inherits System.Windows.Forms.TextBox
End Class
Sub BuildIt()
Dim l As Columns
Dim j As Integer
Static rowtop As Integer
For j = 0 To 2
Dim r As New Panel
With r
..Width = Me.Width
..Top = rowtop
..Height = 24
..Left = 0
rowtop += .Height
End With
Static left As Integer
left = 0
For Each l In Me.m_ColumnHeaders
' Me.Controls.Add(l)
Dim tb As New Columns
With tb
'this is fine but what about databinding
Dim s As String
s = l.DataBindings.Item(0).BindingMemberInfo.BindingFi eld().ToString
..Left = left
left = left + .Width + 2
..Text = l.Text
Try
..DataBindings.Add("Text", Datasource, s)
Catch ex As Exception
End Try
End With
r.Controls.Add(tb)
Next
Me.Controls.Add(r)
Next
End Sub

Nov 20 '05 #1
2 4493
Hello,

"Nathan Carroll" <th************@Bhutan.com> schrieb:
My question is it possible to copy/clone from the collection of the user
control. When i try to add the control from the collection I am only able
to add one control. See Below BuiltIt. [...] Me.Controls.Add(r)


Maybe you can use 'Me.Controls.AddRange' to add an array of controls.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2
Not sure that I used it right but when I tried suggestion ended up with only
one control. Trying to get three panels each with controls that corresponds
to the controls in collection.

Dim NewCol As Columns = New Columns
Sub BuildIt()
Dim l As Columns
Dim j As Integer
Static rowtop As Integer
For j = 0 To 2
Dim r As New Panel
With r
..Width = Me.Width
..Top = rowtop
..Height = 24
..Left = 0
rowtop += .Height
End With
Static left As Integer
left = 0
For Each l In Me.m_ColumnHeaders
'if i place
'Dim NewCol As Columns = New Columns
'here, then the control seems to be added once and for each panel and
subtracted on subsequent additions

' Me.Controls.Add(l)
Dim tb As New Columns
With tb
'this is fine but what about databinding
Dim s As String
s = l.DataBindings.Item(0).BindingMemberInfo.BindingFi eld().ToString
..Left = left
left = left + .Width + 2
..Text = l.Text
Try
..DataBindings.Add("Text", Datasource, s)
Catch ex As Exception
End Try
End With
'allows only one addition
NewCol = l
r.Controls.AddRange(New Control() {NewCol})

'will allow multiples
'r.Controls.Add(tb)
Next

'have no problem with this step
Me.Controls.Add(r)
Next
End Sub

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:#I**************@TK2MSFTNGP12.phx.gbl...
Hello,

"Nathan Carroll" <th************@Bhutan.com> schrieb:
My question is it possible to copy/clone from the collection of the user
control. When i try to add the control from the collection I am only able to add one control. See Below BuiltIt.

[...]
Me.Controls.Add(r)


Maybe you can use 'Me.Controls.AddRange' to add an array of controls.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Will | last post by:
Hi all. I'm learning VB.Net and am developing a WinForms app. I'm trying to make an app that I will use to scan in one or more than on image. I want to use a tabbed interface to hold each image....
2
by: theComputer7 | last post by:
I cut down the code to make this half way understandable... I have read Data Grid girls caution about over use of dynamic controls. I truly believe what I am doing requires dynamically inserted...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
0
by: pbb | last post by:
I have a web page on which I dynamically create controls based on the selection a user makes from a dropdownlist (this ddl is not dynamic). Depending on the user's selection, the controls could be...
1
by: Diffident | last post by:
Hello All, I am trying to add dynamic controls onto my page and here is how I am doing that. I have a page which has a button called as "AddMoreControls" and in this button's event handler I...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.