473,735 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ComboBox's SelectedIndex Property problem

Hi Everyone,

I am at my wit's end here. I have a combobox (combyQueryTitl e) that I
need to use in order to select a query for my database project. Therefore,
I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a new
selection is made, update the query and refresh the display. The only
problem is that the program seems to inexplicably start with the
..selectedindex property at -1! This makes no sense to me. Furthermore,
this is, apparently, happening *before* my form loads, as not only does the
form not appear on screen, but even when I put a breakpoint at the first
possible line within the form_load handler, it still crashes; the breakpoint
is never even reached. Is there a way to locate the point at which the
property is being changed to (or created with) the value of -1? It seems to
me that it should not happen at all.
Please respond here, if possible; if you need more info, you can reach
me via AIM at ajeric74. Thank you!

-- Eric
Nov 21 '05 #1
5 9163
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
Then cmbComboBox.Sel ectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
cmbComboBox.Sel ectedIndex = 0

Can't you exit event _SelectedIndexC hanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With
"Eric A. Johnson" <no*****@dontlo okforme.com> schreef in bericht
news:7Q******** **********@news svr14.news.prod igy.com...
Hi Everyone,

I am at my wit's end here. I have a combobox (combyQueryTitl e) that I
need to use in order to select a query for my database project.
Therefore,
I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a new
selection is made, update the query and refresh the display. The only
problem is that the program seems to inexplicably start with the
.selectedindex property at -1! This makes no sense to me. Furthermore,
this is, apparently, happening *before* my form loads, as not only does
the
form not appear on screen, but even when I put a breakpoint at the first
possible line within the form_load handler, it still crashes; the
breakpoint
is never even reached. Is there a way to locate the point at which the
property is being changed to (or created with) the value of -1? It seems
to
me that it should not happen at all.
Please respond here, if possible; if you need more info, you can reach
me via AIM at ajeric74. Thank you!

-- Eric

Nov 21 '05 #2

"Qwert" <no**@nosp.co m> wrote in message
news:Wc******** ************@ca sema.nl...
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
Then cmbComboBox.Sel ectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
cmbComboBox.Sel ectedIndex = 0

Can't you exit event _SelectedIndexC hanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With


I would like to ask for a side question.
If that is -1 (by default), how do I set the combo text when there is no
selection? Something like web pages "(Please choose a category from
list)"...

That will help a lot. TIA.

Boo K.M.
Nov 21 '05 #3
Better form would be

If not me.cmbComboBox. selectedindex=-1 then
'do something
end if

put that inside your handler....
--
--Eric Cathell, MCSA
"Qwert" <no**@nosp.co m> wrote in message
news:Wc******** ************@ca sema.nl...
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
Then cmbComboBox.Sel ectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
cmbComboBox.Sel ectedIndex = 0

Can't you exit event _SelectedIndexC hanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With
"Eric A. Johnson" <no*****@dontlo okforme.com> schreef in bericht
news:7Q******** **********@news svr14.news.prod igy.com...
Hi Everyone,

I am at my wit's end here. I have a combobox (combyQueryTitl e) that I
need to use in order to select a query for my database project.
Therefore,
I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a
new
selection is made, update the query and refresh the display. The only
problem is that the program seems to inexplicably start with the
.selectedindex property at -1! This makes no sense to me. Furthermore,
this is, apparently, happening *before* my form loads, as not only does
the
form not appear on screen, but even when I put a breakpoint at the first
possible line within the form_load handler, it still crashes; the
breakpoint
is never even reached. Is there a way to locate the point at which the
property is being changed to (or created with) the value of -1? It seems
to
me that it should not happen at all.
Please respond here, if possible; if you need more info, you can reach
me via AIM at ajeric74. Thank you!

-- Eric


Nov 21 '05 #4
Hard code that as your first selection. Then when you bind the datasource it
should fill in under that selection.

-1 means the control is initializing or is stateless(I think I read that on
MSDN) Once the form is loaded the default index=0

combo box's can be a pain....
--
--Eric Cathell, MCSA
"Boo K.M." <bo************ @bkm-researcher.com> wrote in message
news:43******** @news.tm.net.my ...

"Qwert" <no**@nosp.co m> wrote in message
news:Wc******** ************@ca sema.nl...
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
Then cmbComboBox.Sel ectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
cmbComboBox.Sel ectedIndex = 0

Can't you exit event _SelectedIndexC hanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With


I would like to ask for a side question.
If that is -1 (by default), how do I set the combo text when there is no
selection? Something like web pages "(Please choose a category from
list)"...

That will help a lot. TIA.

Boo K.M.

Nov 21 '05 #5
I think you actually want to use .text value. Actually you can databind the
same combobox to 2 different datasources. So if you have a table that has
the query name, query you could do something like this

cbo.datasource= table
cbo.diplaymembe r=column0name
cbo.databinding .add(new binding("text", table,"column0n ame)
cbo.databinding .add(new binding("valuem ember",table,"c olumn1name)

then you would be able to get the querystring off the .selectedvalue
property.

Play around with it some, I ALWAYS have to tinker with my comboboxes because
it always seems each situation needs a different approach. Combos are a
pain...but thats because they are very powerful.
--
--Eric Cathell, MCSA
"Eric A. Johnson" <no*****@dontlo okforme.com> wrote in message
news:g%******** **********@news svr14.news.prod igy.com...
As a matter of fact, is it possible to get the text associated with an
index within the combobox without actually modifying the .selectedindex
property? It is extremely annoying, trying to change within the program
code the selected index, only to have it crash because... I don't even
know why. I can't understand why it won't allow me to change the selected
index! The tooltip in VB.NET tells me that the .selectedindex method
allows me to get or set the index that is selected. Maybe if someone can
point me to a detailed explanation of this idiotic behavior and how to
work around it? I just want the invisible combobox's index to be the same
as the visible one. My AIM name is ajeric74... SOMEBODY please come online
to help me!!!

-- Eric

"Eric A. Johnson" <no*****@dontlo okforme.com> wrote in message
news:vM******** *********@newss vr14.news.prodi gy.com...
Okay, I have another question: What I'm trying to do is to use an
ordinary combobox to hold the query title, and an invisible combobox to
hold the actual query. I want to make it so that the invisible combobox
will change to match the visible one, thereby allowing its .text property
to contain the proper query. Is that possible?

TIA,
Eric

"ECathell" <ec******@nospa m.com> wrote in message
news:Og******** ********@tk2msf tngp13.phx.gbl. ..
Better form would be

If not me.cmbComboBox. selectedindex=-1 then
'do something
end if

put that inside your handler....
--
--Eric Cathell, MCSA
"Qwert" <no**@nosp.co m> wrote in message
news:Wc******** ************@ca sema.nl...
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
Then cmbComboBox.Sel ectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
cmbComboBox.Sel ectedIndex = 0

Can't you exit event _SelectedIndexC hanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With
"Eric A. Johnson" <no*****@dontlo okforme.com> schreef in bericht
news:7Q******** **********@news svr14.news.prod igy.com...
> Hi Everyone,
>
> I am at my wit's end here. I have a combobox (combyQueryTitl e)
> that I
> need to use in order to select a query for my database project.
> Therefore,
> I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a
> new
> selection is made, update the query and refresh the display. The only
> problem is that the program seems to inexplicably start with the
> .selectedindex property at -1! This makes no sense to me.
> Furthermore,
> this is, apparently, happening *before* my form loads, as not only
> does the
> form not appear on screen, but even when I put a breakpoint at the
> first
> possible line within the form_load handler, it still crashes; the
> breakpoint
> is never even reached. Is there a way to locate the point at which
> the
> property is being changed to (or created with) the value of -1? It
> seems to
> me that it should not happen at all.
> Please respond here, if possible; if you need more info, you can
> reach
> me via AIM at ajeric74. Thank you!
>
> -- Eric
>
>



Nov 21 '05 #6

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

Similar topics

2
4529
by: ross kerr | last post by:
Hi all, I have a control that extends the ComboBox object. It updates the selected item based on what the user enters in the text area. In the OnLeave event of the combobox, the selected index is set to the proper item. However, when accessing its selectedindex later it has reverted to the previous value. The selectedindex value is always one behind what
3
4674
by: Nikhil Patel | last post by:
Hi all, I am using the standard System.Windows.Forms.ComboBox controls on a form. There are 5 or 6 comboboxes and their selection depends on each other. The comboboxes behave strangely probably because there are two properties called SelectedIndex and selectedIndex. Both usually have different values. Has anyone experienced any problems using comboboxes? Thanks.
9
56524
by: Steffen Laser | last post by:
Hi group, I have a problem that I already have posted to the german C# newsgroup. Since nobody could help me there, I'd like to try it here again: I set the selected item of a combobox like this: myCombo.SelectedItem = 3; But after that the ComboBox displays only the first entry of the list. When I add the line
7
20767
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well. The control populates well, both the display values, and selected values. However, when i try to "set" the SelectedValue or SelectedIndex properties, nothing happens.... The default blank value in the ComboBox is always selected. My code is: ...
12
5098
by: Steve Dyte | last post by:
Hi, I've narrowed down a problem I've been having filling a combobox with the results of a query stored in a datatable. I'm setting the ValueMember and DisplayMember to the relevant column names, and then I want to make sure nothing is selected. By default it appears that if you do nothing, the first item (0) is selected. However, I want to set the SelectedIndex to -1.
30
4597
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
5
3190
by: Peter M. | last post by:
I'm struggling with combobox databinding with something I consider a bug... I'm binding my combobox to an array of structs. The struct exposes two public properties, ID and Name, to be used as the value and displaymember properties. This works fine. My combobox contains the correct data. However I'm also binding my SelectedValue property to a column in a datatable. Here's where I'm lost. The combobox doesn't show the correct
0
2017
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number of different screens down to a minimum, I'm trying to use the same Windows Forms for both browsing and for updating. This works fine for TextBoxes, but I'm running into problems with my DropDownLists (ComboBoxes).
5
18744
by: Kevinp | last post by:
I've spent the last four hours Google searching for a way to disable items in a Combobox. I found one example in C++ which I can't get to work and another in C# that I couldn't get to work either. Does anyone have some good code for an owner-drawn combobox?
0
8964
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
8786
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
9466
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
9327
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
9201
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
6049
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
4564
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...
0
4823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2190
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.