473,881 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop in Combobox

Hi All:

I would like to know if I can loop my selection in a combobox. For
instance, I got 8 items in a combobox, and when I selected it using the up
and down arrow, it will stop in the first record even I keep on press the up
arrow, on the other hand, if it's the last selection, it will stop in the
last record even I keep on press the down arrow. Is there any way that if I
keep on press the up or down arrow, the slection in it will keep on moving
such as if i am at the first record, and I press the up asrrow, then it will
goto the last selection record, another way is, if i am at the last record
and I keep on press the down arrow, it will goback to the first record. Hope
someone can help me out!

Best rgds,
Ivan Vong
--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
3 1684
Ivan,
I would like to know if I can loop my selection in a combobox. For
instance, I got 8 items in a combobox, and when I selected it using the up
and down arrow, it will stop in the first record even I keep on press the
up
arrow, on the other hand, if it's the last selection, it will stop in the
last record even I keep on press the down arrow. Is there any way that if
I
keep on press the up or down arrow, the slection in it will keep on moving
such as if i am at the first record, and I press the up asrrow, then it
will
goto the last selection record, another way is, if i am at the last record
and I keep on press the down arrow, it will goback to the first record.
Hope
someone can help me out!

What do you mean with a down and with an up arrow from a combobox?

I can also not understand how you would achieve this with a combobox, with a
listbox I can understand it with some extra buttons on a form or with an
extra scrollbar

Cor
Nov 21 '05 #2
"Ivan V via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in message news:52******** ***@DotNetMonst er.com...
Hi All:

I would like to know if I can loop my selection in a combobox. For
instance, I got 8 items in a combobox, and when I selected it using the up
and down arrow, it will stop in the first record even I keep on press the up
arrow, on the other hand, if it's the last selection, it will stop in the
last record even I keep on press the down arrow. Is there any way that if I
keep on press the up or down arrow, the slection in it will keep on moving
such as if i am at the first record, and I press the up asrrow, then it will
goto the last selection record, another way is, if i am at the last record
and I keep on press the down arrow, it will goback to the first record. Hope
someone can help me out!

Best rgds,
Ivan Vong
--
Message posted via http://www.dotnetmonster.com


Assuming you have a ComboBox named ComboBox1 on a form and it has items in the Items collection, I think this may give you a start.

/////
Private Sub ComboBox1_KeyDo wn(ByVal sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles ComboBox1.KeyDo wn

Dim cbo As ComboBox = DirectCast(send er, ComboBox)

If e.KeyCode = Keys.Down Then

If cbo.SelectedInd ex < cbo.Items.Count - 1 Then

cbo.SelectedInd ex += 1

ElseIf cbo.SelectedInd ex = cbo.Items.Count - 1 Then

cbo.SelectedInd ex = 0

End If

e.Handled = True

ElseIf e.KeyCode = Keys.Up Then

If cbo.SelectedInd ex > 0 Then

cbo.SelectedInd ex -= 1

ElseIf cbo.SelectedInd ex = 0 Then

cbo.SelectedInd ex = cbo.Items.Count - 1

End If

e.Handled = True

End If

End Sub
\\\\\\

I'm sure you will need to clean it up abit and tailor it to suite your needs, but it's a start.

--
Al Reid
Nov 21 '05 #3
"Ivan V via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in message
news:52******** ***@DotNetMonst er.com...
if i am at the first record, and I press the up asrrow, then it will goto
the last selection record, another way is, if i am at the last record and
I keep on press the down arrow, it will goback to the first record.


Try handling the KeyUp Event on the ComboBox : (air-code)

Private Sub Combo1_KeyUp(se nder ..., e ...) _
Handles Combo1.KeyUp

With Combo1
If e.KeyCode = Keys.Up _
And .SelectedIndex = 0 _
Then
.SelectedIndex = .Items.Count - 1
e.Handled = True

ElseIf e.KeyCode = Keys.Down _
And .SelectedIndex = .Items.Count - 1 _
Then
.SelectedIndex = 0
e.Handled = True

End If

End With

End Sub

HTH,
Phill W.
Nov 21 '05 #4

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

Similar topics

1
6530
by: - ions | last post by:
Hi, im a just wondering how to add elements into a JComboBox through a loop ie. just say i wanted to add the numbers 1 throught to 100. It seems easy but im having a bit of trouble. One problem which i have had is that i end up only adding the last number (100) to the ComboBox. Any help appreciated :)
7
8543
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way of doing it. I have a table with products, tblProducts, some of them are Active while others are Inactive. The form shows all the products purchased by a customer, both Active and Inactive in a ComboBox, cbProducts. My client wants to view all...
4
1965
by: NCrum | last post by:
I have a while loop which seems to run twice, I call one routine from another once the first loop is completed it returns to the calling routine (the line above) and runs again Calling routine() { ComboBox.FindStringExact(Textbox.text); // routine to be called runs from the //next line then returns to this line and
3
6839
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article: http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/default.aspx I have a problem when there are two DataGrid's on one form, and when I switch focus from one grid to the other. To be more precise, when I'm editing a combo box column in one grid, and then click in the combo column of...
6
1576
by: kberry | last post by:
I am clearing Textboxes on a form... this is loop I have came up with but was wondering if it can be shorter or not as long... Can anyone help? Dim controlOnForm As Control 'Places a control on the form Dim controlOnTab As Control 'Places a control on the tab Dim controlTabPage As Control 'Places a control on the tab page Dim controlGroupBox As Control 'Places a control on the group box
1
1749
by: Rejimonb | last post by:
Can I fill a combobox without using a loop. Using a loop will be time consuming. Reji
1
1075
by: SkyTV | last post by:
i have got 15 combo Boxs on the form they are named cbo1 - cbo15 the following works just fun strY= cbo1.Text; but i wanna learn the for loop way to do it.... i have tried many times...can't figure this out.
4
1913
by: jbott59 | last post by:
I have 10 comboboxes. i would like to run a loop that would reference each combo box and resets certain values. The comboboxes are named ComboBox1, Combobox2, ..... ComboBox10. Here is a sample of what i want. The error returned is "Sub or Function not defined". Public Sub ResetValues() For i = 1 to 10 ComboBox(i).listfillrange="" 'the code errors here where I want to call the combobox ComboBox(i).visible =...
3
1238
by: cmdolcet69 | last post by:
I need to loop through a index change event, however whenever i loop through the first combo box always report back correctly its when i move to the next combobox, that instead of changing the second combo box it will change the background of the first combo box. What im i doing wrong? For intloop = 0 To cboArraylist.Count - 1 If (CType(cboArraylist(intloop), ComboBox).Text) = "Go" Then
0
9926
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11095
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10716
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10399
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9552
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7108
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5780
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.