473,394 Members | 1,866 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,394 software developers and data experts.

Items

I need to browse all ITEMS of a ListBox and all ITEMS of a ComboBox.
I wrote 2 distinct Sub that are almost identical. The difference is only the
object type. How could I browsing ITEMS using only one Sub with object as
parameter?

Here, my two Subs. Thanks

Private Sub AnalyzeListBox()
Dim sText as String
Dim objCtrl As System.Windows.Forms.ListBox = Form1.ListBox1
For i = 0 To objCtrl.Items.Count - 1
Dim objNewElement As New OneElement
sText = objCtrl.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub
Private Sub AnalyzeComboBox()
Dim sText as String
Dim objCtrl As System.Windows.Forms.ComboBox = Form1.ComboBox1
For i = 0 To objCtrl.Items.Count - 1
Dim objNewElement As New OneElement
sText = objCtrl.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub

Nov 20 '05 #1
5 1753
Hi Wally,

You could pass the actual control as a parameter:

Private Sub AnalyzeControl(ByRef myControl As Control)
Dim sText As String
Dim i As Integer

If TypeOf myControl Is ListBox Then
With DirectCast(myControl, ListBox)
For i = 0 To .Items.Count - 1
Dim objNewElement As New OneElement
sText = .Items(i).ToString
Console.WriteLine(sText)
Next
End With

ElseIf TypeOf myControl Is ComboBox Then
With DirectCast(myControl, ComboBox)
For i = 0 To .Items.Count - 1
Dim objNewElement As New OneElement
sText = .Items(i).ToString
Console.WriteLine(sText)
Next
End With
End If
End Sub

Take care,

Eric

"Wally" <va****@nospamcambieri.it> wrote in message
news:9R***********************@news3.tin.it...
I need to browse all ITEMS of a ListBox and all ITEMS of a ComboBox.
I wrote 2 distinct Sub that are almost identical. The difference is only the object type. How could I browsing ITEMS using only one Sub with object as
parameter?

Here, my two Subs. Thanks

Private Sub AnalyzeListBox()
Dim sText as String
Dim objCtrl As System.Windows.Forms.ListBox = Form1.ListBox1
For i = 0 To objCtrl.Items.Count - 1
Dim objNewElement As New OneElement
sText = objCtrl.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub
Private Sub AnalyzeComboBox()
Dim sText as String
Dim objCtrl As System.Windows.Forms.ComboBox = Form1.ComboBox1
For i = 0 To objCtrl.Items.Count - 1
Dim objNewElement As New OneElement
sText = objCtrl.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub

Nov 20 '05 #2
Hi Wally,

You can try this,

I hope it helps?

Cor
\\\
AnalyzeListBox(me.Listbox1)
''''''
Private Sub AnalyzeListBox(byval lc as listcontrol)
Dim sText as String
For i = 0 To lc.Items.Count - 1
Dim objNewElement As New OneElement
sText = lc.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub
///
Nov 20 '05 #3
Thanks Eric, but this solution doesn't solve the problem. It is only one SUB
but most statements are repeated twice. I'm looking for a solution that
doesn't need repeated statements.
P.S.: sorry if my english is not good.... I'm italian! :-)

W
"Eric Lemmon" <E_********************@hotmail.com> ha scritto nel messaggio
news:e4**************@TK2MSFTNGP09.phx.gbl...
Hi Wally,

You could pass the actual control as a parameter:

Private Sub AnalyzeControl(ByRef myControl As Control)
Dim sText As String
Dim i As Integer

If TypeOf myControl Is ListBox Then
With DirectCast(myControl, ListBox)
For i = 0 To .Items.Count - 1
Dim objNewElement As New OneElement
sText = .Items(i).ToString
Console.WriteLine(sText)
Next
End With

ElseIf TypeOf myControl Is ComboBox Then
With DirectCast(myControl, ComboBox)
For i = 0 To .Items.Count - 1
Dim objNewElement As New OneElement
sText = .Items(i).ToString
Console.WriteLine(sText)
Next
End With
End If
End Sub

Take care,

Eric

"Wally" <va****@nospamcambieri.it> wrote in message
news:9R***********************@news3.tin.it...
I need to browse all ITEMS of a ListBox and all ITEMS of a ComboBox.
I wrote 2 distinct Sub that are almost identical. The difference is only

the
object type. How could I browsing ITEMS using only one Sub with object as parameter?

Here, my two Subs. Thanks

Private Sub AnalyzeListBox()
Dim sText as String
Dim objCtrl As System.Windows.Forms.ListBox = Form1.ListBox1
For i = 0 To objCtrl.Items.Count - 1
Dim objNewElement As New OneElement
sText = objCtrl.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub
Private Sub AnalyzeComboBox()
Dim sText as String
Dim objCtrl As System.Windows.Forms.ComboBox = Form1.ComboBox1
For i = 0 To objCtrl.Items.Count - 1
Dim objNewElement As New OneElement
sText = objCtrl.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub


Nov 20 '05 #4
* "Wally" <va****@nospamcambieri.it> scripsit:
I need to browse all ITEMS of a ListBox and all ITEMS of a ComboBox.
I wrote 2 distinct Sub that are almost identical. The difference is only the
object type. How could I browsing ITEMS using only one Sub with object as
parameter? [...] Private Sub AnalyzeListBox()
Dim sText as String
Dim objCtrl As System.Windows.Forms.ListBox = Form1.ListBox1
Declare 'objCtrl' as 'System.Windows.Forms.ListControl'. Then you can
use the same routine for listboxes and comboboxes. ListBox and ComboBox
inherit from this class.
For i = 0 To objCtrl.Items.Count - 1
Dim objNewElement As New OneElement
sText = objCtrl.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub


\\\
Imports System.Windows.Forms
..
..
..
Public Sub AnalyzeListControl(ByVal TheControl As ListControl)
...
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Hi Wally

That objNew element can go as well of course.
\\\
AnalyzeListBox(me.Listbox1)
''''''
Private Sub AnalyzeListBox(byval lc as listcontrol)
Dim sText as String
For i = 0 To lc.Items.Count - 1
sText = lc.Items(i).ToString
Console.WriteLine(sText)
Next
End Sub
///

Nov 20 '05 #6

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

Similar topics

12
by: Donnal Walter | last post by:
The following method is defined in one of my classes: def setup(self, items={}): """perform setup based on a dictionary of items""" if 'something' in items: value = items # now do something...
4
by: mb | last post by:
what is the best way to do this: In a game I want to a class called "Items". This class will have the game items public class Items { public int Chair public int Table . . .and so on . . .
9
by: Alpha | last post by:
Hi, How can I set all the items in a listbox to be selected? I can't find a property or mehtod to do it so I thought I'll try using setselected method but I need to find out how many items are in...
2
by: dave | last post by:
This little problem is driving me nuts!! On my webform page I create 2 variables.. Protected p_dml As String = "I" Public Const mwv_id As Integer = 0 ' originally had mwv_id as Protected
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
2
by: hsuntn | last post by:
I am grabbing Outlook MailItems using the Items property on my Outlook inbox. When I iterate through them, I notice that they are not ordered in ReceivedTime or CreationTime order. For example, ...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
13
by: Joel Koltner | last post by:
Is there an easy way to get a list comprehension to produce a flat list of, say, for each input argument? E.g., I'd like to do something like: for x in range(4) ] ....and receive
13
by: PetterL | last post by:
I writing a program where I read menu items from a file. But I have problem when I click an menu item i want it to mark that one as checked but I cant access the menu object of that item to see...
2
by: mygirl22 | last post by:
Hi, I used this code to created 2 combo boxes General and Specific...and Only show Specific (Combo B) when Combo A is chosen..... What i need now is to know how to assign specific values to the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.