Click here to Skip to main content

.NET Framework

 
GeneralRe: .netframework PinmemberKevin Bewley14-Jan-13 0:46 
AnswerRe: .netframework Pinmemberjibesh11-Dec-12 11:36 
QuestionEnter 3 dates and display order in different VIEW, after click PinmemberxnaLearner7-Dec-12 10:52 
Question[VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) Pinmembersteve_94966136-Dec-12 22:37 
AnswerRe: [VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) PinmemberZaf Khan10-Dec-12 18:57 
GeneralRe: [VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) Pinmembersteve_949661311-Dec-12 22:20 
GeneralRe: [VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) PinmemberZaf Khan12-Dec-12 3:13 
Question[VB.NET 2008] How to get control on objects created at runtime Pinmembersteve_94966135-Dec-12 5:54 
AnswerRe: [VB.NET 2008] How to get control on objects created at runtime PinmemberEddy Vluggen5-Dec-12 6:40 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime Pinmembersteve_94966135-Dec-12 21:59 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime PinmemberEddy Vluggen6-Dec-12 3:27 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime Pinmembersteve_94966136-Dec-12 4:26 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime PinmemberEddy Vluggen6-Dec-12 6:02 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime Pinmembersteve_94966136-Dec-12 22:25 
Thanks for your reply.
Try and try at the end I've found a solution that I'll show you, but I have some questions before.
 
Eddy Vluggen wrote:
"NUD1", the name-property of the UpDown control, must be unique within the form. It'll generate a variable with that name, and that's what "NUD1" points to; it's not a property of the tabpage, it's the name of a single control.

...and that was the problem: I put a NumericUpDown control in a UserControl and I give it an unique name (NUD1). When, at runtime, I create 10 instances of the UserControl, what are the unique names of the 10 NumericUpDown controls originated from NUD1?
 
If I make the value of the NumericUpDown available over a property like this (if I'm not wrong):
Public Property NUDVal() As Int32
  Get
    Return NUD1.Value
  End Get
  Set(ByVal value As Int32)
    NUD1.Value = value
  End Set
End Property
also this property has a unique name... until the UserControl is one, but when I create 10 instances of the UserControl?
 
So I thought to lists of objects... and that is my solution.
 
In the UserControl I created my two NumericUpDown controls at runtime, not in the designer, and I added them to an ArrayList. I also added a CheckBox, in the designer, to use the event "Click" for calculations that serve.
In Form1, the main form, when I create the 10 instances of the UserControl, I also add the ArrayList of controls of every UserControl to another ArrayList declared in the form... here is the code:
'User control
Public Class base
  'list that will contain the controls
  Public Objs As ArrayList = New ArrayList
  'controls
  Private n1, n2 As NumericUpDown
 
  Sub New()
    Dim pos As Point
 
    ' Chiamata richiesta da Progettazione Windows Form.
    InitializeComponent()
 
    ' Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent().
    n1 = New NumericUpDown
    pos.X = 209
    pos.Y = 90
    n1.Location = pos
    Controls.Add(n1)
    n2 = New NumericUpDown
    pos.X = 209
    pos.Y = 132
    n2.Location = pos
    Controls.Add(n2)
    'I add the controls to the list
    Objs.Add(n1)
    Objs.Add(n2)
 
  End Sub
 
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'go to next page
    CType(Parent.Parent, TabControl).SelectedIndex += 1
  End Sub
 
  Private Sub CheckBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.Click
    Dim val1, val2, id, curid As Int32
 
    'index of the current page
    id = CType(Parent.Parent, TabControl).SelectedIndex
    'index in the arraylist of the objects of this page
    curid = id - 1
    'if I am in the third tab... the first useful, that is the second created at runtime
    If curid > 0 Then
      'value of the first NumericUpDown of the previous page
      val1 = CType(CType(Form1.ObjsUC.Item(curid - 1), ArrayList).Item(0), NumericUpDown).Value
      'value of the second NumericUpDown of the previous page
      val2 = CType(CType(Form1.ObjsUC.Item(curid - 1), ArrayList).Item(1), NumericUpDown).Value
      'value of the first NumericUpDown of the current page
      n1.Value = val1 + val2
    End If
  End Sub
 
End Class
 
'Form1
Public Class Form1
  'list that will contain the lists of controls
  Public ObjsUC As ArrayList = New ArrayList
 
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim mypag As TabPage
    Dim myuc As base
 
    For i As Int32 = 0 To 10
      mypag = New TabPage
      myuc = New base
      myuc.Parent = mypag
      'I add the list to the list
      ObjsUC.Add(myuc.Objs)
      mypag.Text = "Pag" & i.ToString
      mypag.Name = "Pag" & i.ToString
      TabControl1.TabPages.Insert(1 + i, mypag)
    Next
 
  End Sub
 
End Class
In this way all the controls I need are inside a list, and I know what kind of object is every element of the list because I put them in the list, I don't need to loop in the list and check each element.
So in the "Click" event of the CheckBox I can "reach" the values of the NumericUpDown controls of the previous page (or of other pages) pointing to them in the list.
 
Well... it works... although I have some difficulty in evaluate the elegance of this code...
 
What do you think about this solution?
 
And I have another question about the pages of the TabControl, but for this I open another topic...
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime PinmemberEddy Vluggen7-Dec-12 2:16 
QuestionTesting Practices PinmemberAndrew Stoute5-Dec-12 5:44 
AnswerRe: Testing Practices PinmemberEddy Vluggen5-Dec-12 6:36 
GeneralRe: Testing Practices PinmemberAndrew Stoute5-Dec-12 6:45 
GeneralRe: Testing Practices PinmemberEddy Vluggen5-Dec-12 6:53 
GeneralRe: Testing Practices PinmvpDave Kreskowiak5-Dec-12 7:29 
GeneralRe: Testing Practices PinmvpDave Kreskowiak5-Dec-12 7:26 
GeneralRe: Testing Practices PinmemberEddy Vluggen5-Dec-12 7:34 
GeneralRe: Testing Practices PinmvpDave Kreskowiak5-Dec-12 10:55 
GeneralRe: Testing Practices PinmemberEddy Vluggen6-Dec-12 1:08 
QuestionHow to make a list view and gallerie view on a product page list on some e-commerce PinmemberEl daniel4-Dec-12 1:19 
AnswerRe: How to make a list view and gallerie view on a product page list on some e-commerce PinmemberEddy Vluggen4-Dec-12 1:37 
Questionframework 2.0 and win98 Pinmembercaradri3-Dec-12 23:37 
AnswerRe: framework 2.0 and win98 PinmvpRichard MacCutchan4-Dec-12 0:01 
AnswerRe: framework 2.0 and win98 PinmemberEddy Vluggen4-Dec-12 0:04 
AnswerRe: framework 2.0 and win98 PinprotectorPete O'Hanlon4-Dec-12 0:07 
GeneralRe: framework 2.0 and win98 PinmemberEddy Vluggen4-Dec-12 0:31 
GeneralRe: framework 2.0 and win98 PinprotectorPete O'Hanlon4-Dec-12 0:38 
GeneralRe: framework 2.0 and win98 PinmemberEddy Vluggen4-Dec-12 0:43 
GeneralRe: framework 2.0 and win98 PinprotectorPete O'Hanlon4-Dec-12 0:41 
GeneralRe: framework 2.0 and win98 Pinmembercaradri4-Dec-12 1:25 
GeneralRe: framework 2.0 and win98 PinmvpDave Kreskowiak4-Dec-12 5:11 
GeneralRe: framework 2.0 and win98 Pinmembercaradri4-Dec-12 1:23 
GeneralRe: framework 2.0 and win98 PinmemberEddy Vluggen4-Dec-12 1:36 
GeneralRe: framework 2.0 and win98 Pinmembercaradri4-Dec-12 2:52 
GeneralRe: framework 2.0 and win98 PinprotectorPete O'Hanlon4-Dec-12 3:11 
GeneralRe: framework 2.0 and win98 PinmemberEddy Vluggen4-Dec-12 3:56 
Questionjquery.datePicker not working PinmemberxnaLearner3-Dec-12 7:27 
AnswerRe: jquery.datePicker not working [modified] PinprotectorPete O'Hanlon3-Dec-12 7:38 
QuestionOOPS concepts in c# Pinmember95003940022-Dec-12 18:09 
AnswerRe: OOPS concepts in c# PinmvpRichard MacCutchan2-Dec-12 22:43 
AnswerRe: OOPS concepts in c# PinmemberEddy Vluggen3-Dec-12 2:00 
GeneralRe: OOPS concepts in c# Pinmember95003940023-Dec-12 2:49 
GeneralRe: OOPS concepts in c# PinmemberEddy Vluggen3-Dec-12 4:17 
AnswerRe: OOPS concepts in c# PinprotectorPete O'Hanlon3-Dec-12 2:58 
GeneralRe: OOPS concepts in c# Pinmember95003940023-Dec-12 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.150224.1 | Last Updated 28 Feb 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid