473,385 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Remove Button Collection Panel

1
hi,
i have this button collection i add in run time and then remove, but for some reason it is not removed.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Button_Click(ByVal sender As Object, ByVal e As  _
  2.                              System.EventArgs)
  3.  
  4.         ListBox2.Items.Add(CType(CType(sender,  _
  5.           System.Windows.Forms.Button).Text, String))
  6.         Dim stringa() As String = {"1", CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(0, 5), CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(6), "", CType(CType(sender, System.Windows.Forms.Button).Tag, String) + " €"}
  7.         Dim item As New ListViewItem(stringa)
  8.         ListView1.Items.Add(item)
  9.  
  10.         Try
  11.  
  12.             Dim CNT1 As Integer = 0
  13.             Dim CNT2 As Integer = 0
  14.             bottone1 = New Button(ListView1.Items.Count * 4) {}
  15.             bottone2 = New ComboBox(ListView1.Items.Count) {}
  16.  
  17.             Dim X As Integer = ListView1.Location.X - 110
  18.             Dim Y As Integer = ListView1.Location.Y + 25
  19.  
  20.             While CNT1 < ListView1.Items.Count * 4
  21.  
  22.  
  23.                 bottone1(CNT1) = New Button
  24.                 bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  25.                 bottone1(CNT1).Size = New System.Drawing.Size(20, 20)
  26.                 bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  27.                 bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  28.                 bottone1(CNT1).Text = "+"
  29.                 bottone1(CNT1).Tag = CNT2
  30.                 AddHandler bottone1(CNT1).Click, AddressOf bottoni
  31.  
  32.                 Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  33.                 CNT1 += 1
  34.                 X = X + 20
  35.  
  36.                 bottone1(CNT1) = New Button
  37.                 bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  38.                 bottone1(CNT1).Size = New System.Drawing.Size(20, 20)
  39.                 bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  40.                 bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  41.                 bottone1(CNT1).Text = "-"
  42.                 bottone1(CNT1).Tag = CNT2
  43.                 AddHandler bottone1(CNT1).Click, AddressOf bottoni
  44.  
  45.                 Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  46.                 CNT1 += 1
  47.                 X = X + 20
  48.  
  49.                 bottone1(CNT1) = New Button
  50.                 bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  51.                 bottone1(CNT1).Size = New System.Drawing.Size(20, 20)
  52.                 bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  53.                 bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  54.                 bottone1(CNT1).Text = "D"
  55.                 'AddHandler bottone1(CNT).Click, AddressOf Button_Click
  56.  
  57.                 X = X + 20
  58.  
  59.                 bottone2(CNT2) = New ComboBox
  60.                 bottone2(CNT2).Location = New System.Drawing.Point(X, Y)
  61.                 bottone2(CNT2).Size = New System.Drawing.Size(50, 20)
  62.                 'bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  63.                 bottone2(CNT2).ForeColor = System.Drawing.Color.Black
  64.                 'For index = 0 To bottone2(CNT2).Items.Count - 1
  65.                 'If bottone2(CNT2).Items(index).ToString = CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(0, 5) Then
  66.                 'bottone2(CNT2).SelectedIndex = index
  67.                 'Exit For
  68.  
  69.                 'End If
  70.                 'Next
  71.                 'bottone2(CNT2).SelectedItem = CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(0, 5)
  72.                 bottone2(CNT2).DropDownStyle = ComboBoxStyle.DropDownList
  73.                 bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(0).Substring(0, 5))
  74.                 bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(1).Substring(0, 5))
  75.                 bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(2).Substring(0, 5))
  76.                 bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(3).Substring(0, 5))
  77.                 bottone2(CNT2).SelectedItem = CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(0, 5)
  78.                 bottone2(CNT2).Tag = CNT2
  79.                 AddHandler bottone2(CNT2).SelectedValueChanged, AddressOf cambia
  80.  
  81.                 X = X + 20
  82.  
  83.                 Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  84.                 CNT1 += 1
  85.                 Me.SplitContainer1.Panel2.Controls.Add(bottone2(CNT2))
  86.                 CNT2 += 1
  87.                 X = X + 25 + ListView1.Width + 5
  88.  
  89.                 bottone1(CNT1) = New Button
  90.                 bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  91.                 bottone1(CNT1).Size = New System.Drawing.Size(40, 20)
  92.                 bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  93.                 bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  94.                 bottone1(CNT1).Text = "Ingr."
  95.                 AddHandler bottone1(CNT1).Click, AddressOf aggiungi
  96.  
  97.  
  98.                 Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  99.                 CNT1 += 1
  100.                 X = ListView1.Location.X - 110
  101.                 Y = Y + 20
  102.  
  103.  
  104.  
  105.             End While
  106.  
  107.  
  108.  
  109.  
  110.  
  111.         Catch ex As Exception
  112.  
  113.         End Try
  114.  
  115.  
  116.  
  117.  
  118.  
  119.     End Sub
  120.  
And this to remove the buttons.

Expand|Select|Wrap|Line Numbers
  1. Public Sub bottoni(ByVal sender As Button, ByVal e As System.EventArgs)
  2.  
  3.         If sender.Text = "+" Then
  4.             ListView1.Items(Integer.Parse(sender.Tag)).SubItems(0).Text += 1
  5.  
  6.  
  7.         ElseIf sender.Text = "-" Then
  8.             ListView1.Items(Integer.Parse(sender.Tag)).SubItems(0).Text -= 1
  9.  
  10.  
  11.  
  12.             If ListView1.Items(Integer.Parse(sender.Tag)).SubItems(0).Text = 0 Then
  13.  
  14.                 ListView1.Items(Integer.Parse(sender.Tag)).Remove()
  15.  
  16.                 For index = bottone1.Length - 2 to 0 Step -1
  17.  
  18.                     'RemoveHandler bottone1(index).Click, AddressOf bottoni
  19.                     'SplitContainer1.Panel2.Controls.Remove
  20.                     SplitContainer1.Panel2.Controls.Remove(bottone1(index))
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.                 Next
  32.  
  33.                 'bottone1(0).Dispose()
  34.  
  35.                 For index = 0 To bottone2.Length - 2
  36.  
  37.                     'MsgBox(bottone2.Length)
  38.                     SplitContainer1.Panel2.Controls.Remove(bottone2(index))
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.                 Next
  50.  
  51.                 'MsgBox(Me.SplitContainer1.Panel2.Controls.Count)
  52.                 'Dim stringa() As String
  53.                 'Dim z = 0
  54.                 Dim stringa1 As String
  55.                 For Each Control As Object In Me.SplitContainer1.Panel2.Controls
  56.  
  57.                     'stringa(z) = Control.ToString
  58.  
  59.                     stringa1 += vbNewLine + Control.ToString
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.                 Next
  67.  
  68.                 'MsgBox(stringa1)
  69.  
  70.                 'MsgBox("")
  71.                 'MsgBox(SplitContainer1.Panel2.Controls.Count)
  72.  
  73.  
  74.                 Array.Clear(bottone1, 0, bottone1.Count)
  75.                 Array.Resize(bottone1, 0)
  76.                 Array.Clear(bottone2, 0, bottone2.Count)
  77.                 Array.Resize(bottone2, 0)
  78.  
  79.                 Try
  80.  
  81.                     Dim CNT1 As Integer = 0
  82.                     Dim CNT2 As Integer = 0
  83.                     bottone1 = New Button(ListView1.Items.Count * 4) {}
  84.                     bottone2 = New ComboBox(ListView1.Items.Count) {}
  85.  
  86.                     Dim X As Integer = ListView1.Location.X - 110
  87.                     Dim Y As Integer = ListView1.Location.Y + 25
  88.  
  89.                     While CNT1 < ListView1.Items.Count * 4
  90.  
  91.  
  92.                         bottone1(CNT1) = New Button
  93.                         bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  94.                         bottone1(CNT1).Size = New System.Drawing.Size(20, 20)
  95.                         bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  96.                         bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  97.                         bottone1(CNT1).Text = "+"
  98.                         bottone1(CNT1).Tag = CNT2
  99.                         AddHandler bottone1(CNT1).Click, AddressOf bottoni
  100.  
  101.                         Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  102.                         CNT1 += 1
  103.                         X = X + 20
  104.  
  105.                         bottone1(CNT1) = New Button
  106.                         bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  107.                         bottone1(CNT1).Size = New System.Drawing.Size(20, 20)
  108.                         bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  109.                         bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  110.                         bottone1(CNT1).Text = "-"
  111.                         bottone1(CNT1).Tag = CNT2
  112.                         AddHandler bottone1(CNT1).Click, AddressOf bottoni
  113.  
  114.                         Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  115.                         CNT1 += 1
  116.                         X = X + 20
  117.  
  118.                         bottone1(CNT1) = New Button
  119.                         bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  120.                         bottone1(CNT1).Size = New System.Drawing.Size(20, 20)
  121.                         bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  122.                         bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  123.                         bottone1(CNT1).Text = "D"
  124.                         AddHandler bottone1(CNT1).Click, AddressOf bottoni
  125.  
  126.                         X = X + 20
  127.  
  128.                         bottone2(CNT2) = New ComboBox
  129.                         bottone2(CNT2).Location = New System.Drawing.Point(X, Y)
  130.                         bottone2(CNT2).Size = New System.Drawing.Size(50, 20)
  131.                         'bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  132.                         bottone2(CNT2).ForeColor = System.Drawing.Color.Black
  133.                         'For index = 0 To bottone2(CNT2).Items.Count - 1
  134.                         'If bottone2(CNT2).Items(index).ToString = CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(0, 5) Then
  135.                         'bottone2(CNT2).SelectedIndex = index
  136.                         'Exit For
  137.  
  138.                         'End If
  139.                         'Next
  140.                         'bottone2(CNT2).SelectedItem = CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(0, 5)
  141.                         bottone2(CNT2).DropDownStyle = ComboBoxStyle.DropDownList
  142.                         bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(0).Substring(0, 5))
  143.                         bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(1).Substring(0, 5))
  144.                         bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(2).Substring(0, 5))
  145.                         bottone2(CNT2).Items.Add(FormAggiungi.ComboBox1.Items(3).Substring(0, 5))
  146.                         bottone2(CNT2).SelectedItem = CType(CType(sender, System.Windows.Forms.Button).Text, String).Substring(0, 5)
  147.                         bottone2(CNT2).Tag = CNT2
  148.                         AddHandler bottone2(CNT2).SelectedValueChanged, AddressOf cambia
  149.  
  150.                         X = X + 20
  151.  
  152.                         Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  153.                         CNT1 += 1
  154.                         Me.SplitContainer1.Panel2.Controls.Add(bottone2(CNT2))
  155.                         CNT2 += 1
  156.                         X = X + 25 + ListView1.Width + 5
  157.  
  158.                         bottone1(CNT1) = New Button
  159.                         bottone1(CNT1).Location = New System.Drawing.Point(X, Y)
  160.                         bottone1(CNT1).Size = New System.Drawing.Size(40, 20)
  161.                         bottone1(CNT1).TextAlign = ContentAlignment.MiddleCenter
  162.                         bottone1(CNT1).ForeColor = System.Drawing.Color.Black
  163.                         bottone1(CNT1).Text = "Ingr."
  164.                         AddHandler bottone1(CNT1).Click, AddressOf aggiungi
  165.  
  166.  
  167.                         Me.SplitContainer1.Panel2.Controls.Add(bottone1(CNT1))
  168.                         CNT1 += 1
  169.                         X = ListView1.Location.X - 110
  170.                         Y = Y + 20
  171.  
  172.  
  173.  
  174.                     End While
  175.  
  176.  
  177.  
  178.  
  179.  
  180.                 Catch ex As Exception
  181.  
  182.                 End Try
  183.  
  184.  
  185.  
  186.  
  187.             End If
  188.  
  189.  
  190.         ElseIf sender.Text = "C" Then
  191.             ListView1.Items(Integer.Parse(sender.Tag)).Remove()
  192.             Controls.Remove(bottone1(0))
  193.  
  194.  
  195.         End If
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.     End Sub
Any help would be appreciated eh okk.
Thanks.
Ciao.
Andrea.
Sep 17 '10 #1
0 1242

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jim Mitchell | last post by:
I am using the following code to trap the onclick event for the Toolbar Webcontrol. The problem is that I have no way to tell which button on the toolbar was clicked. Any ideas? Thanks in...
5
by: JohnSouth | last post by:
Hi I've an image submit button on a form that needs to appear flat on the surface. I can't get rid of the shadow that appears bottom and right. This is the best I can do. <code>...
2
by: Ramamoorthy Ramasamy | last post by:
Hi all, I would like to create a page with VBscript and ASP which will contain two list-boxes one in the left side and the other in the right side with two buttons namely "Add>>" and "<<Remove"...
9
by: David | last post by:
hello... i want to renove all controls from panel... i use this: foreach (Control c in panel.Controls) panel.Controls.Remove(c); but it's doesn't work... -- not all controls are removed...
0
by: Dan | last post by:
HI, How can i hide the 2 buttons (next/previous month) in the MonthCalendar Control ? Is there a way to do it ? Thank is advance Dan
2
by: Patrick | last post by:
Hello - I'm working on a VB program that uses two radio button collections - one of State, the other of Capitols. If the state is selected in collection1, then the appropriate capitol is selected...
5
by: Peted | last post by:
I know you can iterate through a collection of radio buttons in a panel, using a "for each in control" type iteration that c# supports, but is it possible to iterate through the radio buttons...
3
by: aryan24 | last post by:
Can anyone please provide the solution to add minimize and close buttons to each panel ., embedded in a frame...
4
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
I have a usercontrol that has a panel as a band across the width of the user control When the usercontrol is diaplayed the button is not centered. If I anchor the button to the panel...
14
by: Adam Sandler | last post by:
I have a class with a method which returns a panel. The panel was not created with the visual editor, I coded it by hand -- because some of the content on the panel can be dynamic and thus I chose...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.